[issue37625] Class variable is still accessible after class instance has been overwritten out

Eric V. Smith report at bugs.python.org
Thu Jul 18 21:21:02 EDT 2019


Eric V. Smith <eric at trueblade.com> added the comment:

Because variable belongs to the class, and not any instance of the class, you can duplicate this behavior without creating any instances at all:

>>> class TestClass(object):
...     variable = []
...
>>> TestClass.variable.append(1)
>>> TestClass.variable
[1]

And then when you create an instance t, t.variable still refers to the class:

>>> t = TestClass()
>>> t.variable
[1]
>>>

This is expected behavior.

----------
nosy: +eric.smith
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37625>
_______________________________________


More information about the Python-bugs-list mailing list