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.
Created on 2012年05月08日 16:48 by mattofak, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (2) | |||
|---|---|---|---|
| msg160212 - (view) | Author: Matthew Walker (mattofak) | Date: 2012年05月08日 16:48 | |
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. |
|||
| msg160213 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2012年05月08日 16:49 | |
This is not a bug, see http://docs.python.org/dev/faq/design.html#why-are-default-values-shared-between-objects |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:30 | admin | set | github: 58961 |
| 2012年05月08日 16:49:44 | pitrou | set | status: open -> closed |
| 2012年05月08日 16:49:39 | pitrou | set | nosy:
+ pitrou messages: + msg160213 resolution: not a bug stage: resolved |
| 2012年05月08日 16:48:55 | mattofak | set | type: behavior |
| 2012年05月08日 16:48:00 | mattofak | create | |