changeset: 99394:fecb07050aae branch: 3.5 parent: 99384:4897438543da parent: 99392:095d21df9374 user: Serhiy Storchaka date: Mon Nov 30 17:35:40 2015 +0200 files: Lib/copy.py Lib/test/test_copy.py Misc/NEWS description: Issue #25718: Fixed copying object with state with boolean value is false. diff -r 4897438543da -r fecb07050aae Lib/copy.py --- a/Lib/copy.py Sun Nov 29 13:13:24 2015 +0200 +++ b/Lib/copy.py Mon Nov 30 17:35:40 2015 +0200 @@ -279,7 +279,7 @@ if n > 2: state = info[2] else: - state = {} + state = None if n > 3: listiter = info[3] else: @@ -293,7 +293,7 @@ y = callable(*args) memo[id(x)] = y - if state: + if state is not None: if deep: state = deepcopy(state, memo) if hasattr(y, '__setstate__'): diff -r 4897438543da -r fecb07050aae Lib/test/test_copy.py --- a/Lib/test/test_copy.py Sun Nov 29 13:13:24 2015 +0200 +++ b/Lib/test/test_copy.py Mon Nov 30 17:35:40 2015 +0200 @@ -213,6 +213,9 @@ return self.foo == other.foo x = C(42) self.assertEqual(copy.copy(x), x) + # State with boolean value is false (issue #25718) + x = C(0.0) + self.assertEqual(copy.copy(x), x) # The deepcopy() method @@ -517,6 +520,12 @@ self.assertEqual(y, x) self.assertIsNot(y, x) self.assertIsNot(y.foo, x.foo) + # State with boolean value is false (issue #25718) + x = C([]) + y = copy.deepcopy(x) + self.assertEqual(y, x) + self.assertIsNot(y, x) + self.assertIsNot(y.foo, x.foo) def test_deepcopy_reflexive_inst(self): class C: diff -r 4897438543da -r fecb07050aae Misc/NEWS --- a/Misc/NEWS Sun Nov 29 13:13:24 2015 +0200 +++ b/Misc/NEWS Mon Nov 30 17:35:40 2015 +0200 @@ -20,6 +20,8 @@ Library ------- +- Issue #25718: Fixed copying object with state with boolean value is false. + - Issue #10131: Fixed deep copying of minidom documents. Based on patch by Marian Ganisin.