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 2008-09-02 01:57 by benjamin.peterson. 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
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