[issue14756] Empty Dict in Initializer is Shared Betwean Objects
Matthew Walker
report at bugs.python.org
Tue May 8 18:48:01 CEST 2012
New submission from Matthew Walker <mattofak at gmail.com>:
When initializing a class with an empty dict() object as a default initializer, if it is not overridden, multiple instances of the class will share the dictionary. IE:
class test(object):
def __init__(self, obj=dict()):
self.obj = obj
a = test()
b = test()
Then id(a.obj) points to the same location as id(b.obj). The behaviour I would expect would be that a.obj and b.obj would be unique instances.
----------
components: Interpreter Core
messages: 160212
nosy: Matthew.Walker
priority: normal
severity: normal
status: open
title: Empty Dict in Initializer is Shared Betwean Objects
versions: Python 2.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14756>
_______________________________________
More information about the Python-bugs-list
mailing list