New submission from Matthew Walker <matto...@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue14756>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to