mirror of
https://github.com/python/cpython.git
synced 2025-11-03 19:34:08 +00:00
Fix from SF patch 565085: copy._reduction doesn't __setstate__.
Straightforward fix. Will backport to 2.2. If there's ever a new 2.1 release, this could be backported there too (since it's an issue with anything that's got both a __reduce__ and a __setstate__).
This commit is contained in:
parent
3e3583c345
commit
a48cb8f77d
1 changed files with 29 additions and 0 deletions
|
|
@ -3071,6 +3071,34 @@ def string_exceptions():
|
||||||
except:
|
except:
|
||||||
raise TestFailed, "string subclass allowed as exception"
|
raise TestFailed, "string subclass allowed as exception"
|
||||||
|
|
||||||
|
def copy_setstate():
|
||||||
|
if verbose:
|
||||||
|
print "Testing that copy.*copy() correctly uses __setstate__..."
|
||||||
|
import copy
|
||||||
|
class C(object):
|
||||||
|
def __init__(self, foo=None):
|
||||||
|
self.foo = foo
|
||||||
|
self.__foo = foo
|
||||||
|
def setfoo(self, foo=None):
|
||||||
|
self.foo = foo
|
||||||
|
def getfoo(self):
|
||||||
|
return self.__foo
|
||||||
|
def __getstate__(self):
|
||||||
|
return [self.foo]
|
||||||
|
def __setstate__(self, lst):
|
||||||
|
assert len(lst) == 1
|
||||||
|
self.__foo = self.foo = lst[0]
|
||||||
|
a = C(42)
|
||||||
|
a.setfoo(24)
|
||||||
|
vereq(a.foo, 24)
|
||||||
|
vereq(a.getfoo(), 42)
|
||||||
|
b = copy.copy(a)
|
||||||
|
vereq(b.foo, 24)
|
||||||
|
vereq(b.getfoo(), 24)
|
||||||
|
b = copy.deepcopy(a)
|
||||||
|
vereq(b.foo, 24)
|
||||||
|
vereq(b.getfoo(), 24)
|
||||||
|
|
||||||
def do_this_first():
|
def do_this_first():
|
||||||
if verbose:
|
if verbose:
|
||||||
print "Testing SF bug 551412 ..."
|
print "Testing SF bug 551412 ..."
|
||||||
|
|
@ -3153,6 +3181,7 @@ def test_main():
|
||||||
imulbug()
|
imulbug()
|
||||||
docdescriptor()
|
docdescriptor()
|
||||||
string_exceptions()
|
string_exceptions()
|
||||||
|
copy_setstate()
|
||||||
if verbose: print "All OK"
|
if verbose: print "All OK"
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue