Re:WTFPython: Exploring and understanding Python through sur...
by dragonwriter on Tuesday May 31, 2022 @06:36AM
(#31567946)
> These assignments work exactly as expected no matter which school of thought you come
No, they don't.
obj.b does not exist, and no assignment to it takes place, and there is no “indirect effect”.
A.b exists, and because class attributes can be accessed as if they were members on instances, and because A.b has an implementation of in-place addition, that implementation is called on A.b instead of an assignment to obj.b. That is the only thing that happens as a result of the statement that looks like it might be an assignment to obj.b. The effect on A.b is the only action, not an indirect effect of an assignment.
No, they don't.
obj.b does not exist, and no assignment to it takes place, and there is no “indirect effect”.
A.b exists, and because class attributes can be accessed as if they were members on instances, and because A.b has an implementation of in-place addition, that implementation is called on A.b instead of an assignment to obj.b. That is the only thing that happens as a result of the statement that looks like it might be an assignment to obj.b. The effect on A.b is the only action, not an indirect effect of an assignment.