homepage

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: copy.copy corrupts objects that return false value from __getstate__
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 2.6, Python 2.5
process
Status: closed Resolution: duplicate
Dependencies: Superseder: deepcopy erroneously doesn't call __setstate__ if __getstate__ returns empty dict
View: 6827
Assigned To: Nosy List: alexandre.vassalotti, alga
Priority: normal Keywords:

Created on 2010年02月03日 18:18 by alga, last changed 2022年04月11日 14:56 by admin. This issue is now closed.

Messages (2)
msg98793 - (view) Author: Albertas Agejevas (alga) Date: 2010年02月03日 18:18
When copy.copy is used on an object whose __getstate__ returns 0, it can produce a corrupt copy of an object:
>>> import copy
>>> class Foo(object):
... def __init__(self):
... self.value = 0
... def __getstate__(self):
... return self.value
... def __setstate__(self, v):
... self.value = v
... 
>>> one = Foo()
>>> two = copy.copy(one)
>>> two.value
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
AttributeError: 'Foo' object has no attribute 'value'
Pickling/unpickling works fine for this object, so this appears to be a bug in copy._reconstruct.
This is not a contrived example, BTrees.Length.Length from ZODB uses such a __getstate__.
msg98822 - (view) Author: Albertas Agejevas (alga) Date: 2010年02月04日 10:09
This bug is a duplicate of issue6827, sorry.
History
Date User Action Args
2022年04月11日 14:56:57adminsetgithub: 52096
2010年02月07日 09:33:11georg.brandlsetstatus: open -> closed
2010年02月04日 16:23:53r.david.murraysetpriority: normal
resolution: duplicate
superseder: deepcopy erroneously doesn't call __setstate__ if __getstate__ returns empty dict
stage: resolved
2010年02月04日 12:43:56pitrousetnosy: + alexandre.vassalotti
2010年02月04日 10:09:45algasetmessages: + msg98822
2010年02月03日 18:18:43algacreate

AltStyle によって変換されたページ (->オリジナル) /