[New-bugs-announce] [issue37625] Class variable is still accessible after class instance has been overwritten out

Daniel report at bugs.python.org
Thu Jul 18 17:55:14 EDT 2019


New submission from Daniel <dan+pythonbug at moird.com>:

Not sure if this is the desired behavior but wanted to bring it up anyways.
When you have a class and have a variable in like:
class TestClass(object):
    variable = []

then you run it through a loop like:
for num in range(10):
    test = TestClass()
    test.variable.append(num)

even if you assign another variable to it or none like:
test = "blah"
test = None

then reassign the class:
test = TestClass()
print(test.variable)

will return all the numbers in the list.
also doesn't seem to matter if garbage collection was manually ran.

Attached is a small example code.
This was found on Macos and tested with both python 3.7 and 2.7 Subsequently same on ubuntu with python 3.5 and python 2.7

----------
components: Interpreter Core
files: variabletest.py
messages: 348130
nosy: moird
priority: normal
severity: normal
status: open
title: Class variable is still accessible after class instance has been overwritten out
type: behavior
versions: Python 2.7, Python 3.5, Python 3.7
Added file: https://bugs.python.org/file48490/variabletest.py

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


More information about the New-bugs-announce mailing list