New submission from Albertas Agejevas <a...@pov.lt>:

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__.

----------
components: Library (Lib)
messages: 98793
nosy: alga
severity: normal
status: open
title: copy.copy corrupts objects that return false value from __getstate__
type: behavior
versions: Python 2.5, Python 2.6, Python 3.1

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue7848>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to