[issue23824] in-place addition of a shadowed class field
Jethro
report at bugs.python.org
Tue Mar 31 16:39:18 CEST 2015
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
>>> addtot(3)
If this tot is allowed to be resolved to different things, there should be no problem. Instead you get an error:
Traceback (most recent call last):
File "<pyshell#106>", line 1, in <module>
addtot(3)
File "<pyshell#105>", line 1, in addtot
def addtot(x): tot += x
UnboundLocalError: local variable 'tot' referenced before assignment
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23824>
_______________________________________
More information about the Python-bugs-list
mailing list