New submission from Daniel <dan+python...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue37625>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to