This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Lists propagate through new instances of class if using append
Type: behavior Stage:
Components: None Versions: Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, supernova_hq
Priority: normal Keywords:

Created on 2008-09-02 00:55 by supernova_hq, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bug_reproduction_test.py supernova_hq, 2008-09-02 00:54 Code to reproduce the test
bug_reproduction_test.py supernova_hq, 2008-09-02 00:57
Messages (3)
msg72305 - (view) Author: (supernova_hq) Date: 2008-09-02 00:54
I have located a bug where every instance of an identical class (or a
class that extends it) will use the same copy of any list element
created before __init__.

The only way I have found to fix this is to explicitly empty the list
inside the __init__ function before the list is used.

Please view and run the attached code for the example.
msg72306 - (view) Author: (supernova_hq) Date: 2008-09-02 00:57
I have located a bug where every instance of an identical class (or a
class that extends it) will use the same copy of any list element
created before __init__.

The only way I have found to fix this is to explicitly empty the list
inside the __init__ function before the list is used.

Please view and run the attached code for the example.
msg72308 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-09-02 01:57
This is the expected behavior. By declaring variables outside class
methods, they become class variables and are associated with the class
instead of the instance.
History
Date User Action Args
2022-04-11 14:56:38adminsetgithub: 48005
2008-09-02 01:57:34benjamin.petersonsetstatus: open -> closed
resolution: not a bug
messages: + msg72308
nosy: + benjamin.peterson
2008-09-02 00:57:17supernova_hqsetfiles: + bug_reproduction_test.py
messages: + msg72306
2008-09-02 00:55:00supernova_hqcreate