[issue23824] in-place addition of a shadowed class field

2015-04-01 Thread R. David Murray
R. David Murray added the comment: And I'm telling you that *this is how Python is designed*, and it is not going to change. Class attributes are *special*, for a reason. Please do not reopen this issue again. If you wish to pursue this further, the language design discussion forum is the py

[issue23824] in-place addition of a shadowed class field

2015-03-31 Thread Jethro
Jethro added the comment: I'm not confused. In my first report, I have already explained why python behaves that way. My point is, this is not the right way to go. Because the very same self.tot in the in-place operation self.tot+=a is first resolved to be the class field, then an instance fie

[issue23824] in-place addition of a shadowed class field

2015-03-31 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- resolution: -> not a bug status: open -> closed ___ Python tracker ___ ___ Python-bugs-list mailing

[issue23824] in-place addition of a shadowed class field

2015-03-31 Thread R. David Murray
R. David Murray added the comment: Ah, now I understand your confusion. Class variables are special. The first time you reference a name on an instance that is not currently defined on that instance but is defined on the class, the interpreter gets the object pointer from the class reference

[issue23824] in-place addition of a shadowed class field

2015-03-31 Thread Jethro
Changes by Jethro : -- resolution: not a bug -> status: closed -> open ___ Python tracker ___ ___ Python-bugs-list mailing list Unsub

[issue23824] in-place addition of a shadowed class field

2015-03-31 Thread Jethro
Jethro added the comment: I believe Mr. Murray somehow missed the point. My point is that the very same self.tot is interpreted as two different things: instance field and class field. In another analogous case, the interpreter would be more consistent: >>> tot = 0 >>> def addtot(x): tot+=x >>

[issue23824] in-place addition of a shadowed class field

2015-03-31 Thread R. David Murray
R. David Murray added the comment: Yep, this is the way it works. When a class attribute name is referenced on an instance object, you are referencing the object pointed to by the class name. What happens next depends on what kind of object you have, and what kind of operation you perform.

[issue23824] in-place addition of a shadowed class field

2015-03-31 Thread Jethro
New submission from Jethro: Look at this simple code: class A: tot = 0 def __init__(self, a): self.tot += a x = A(3) print(x.tot, A.tot) Result from print: 3 0 What the interpreter did was that it first resolved self.tot to be the class field