]> granicus.if.org Git - python/commitdiff
Issue #25718: Fixed copying object with state with boolean value is false.
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 30 Nov 2015 15:20:02 +0000 (17:20 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 30 Nov 2015 15:20:02 +0000 (17:20 +0200)
Lib/copy.py
Lib/test/test_copy.py
Misc/NEWS

index bb8840ed549a5975a2e03b57b9f652e0608beb66..f0fb44377767d61830aca2fd6234a230ee572a35 100644 (file)
@@ -281,7 +281,7 @@ def _reconstruct(x, info, deep, memo=None):
     if n > 2:
         state = info[2]
     else:
-        state = {}
+        state = None
     if n > 3:
         listiter = info[3]
     else:
@@ -295,7 +295,7 @@ def _reconstruct(x, info, deep, memo=None):
     y = callable(*args)
     memo[id(x)] = y
 
-    if state:
+    if state is not None:
         if deep:
             state = deepcopy(state, memo)
         if hasattr(y, '__setstate__'):
index eb8d18cf0b1217490af804bb7a68b86055e89546..0c5354c65c854f1755449e661dc7dfad92b61f38 100644 (file)
@@ -180,6 +180,9 @@ class TestCopy(unittest.TestCase):
                 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
 
@@ -448,6 +451,12 @@ class TestCopy(unittest.TestCase):
         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:
index 95f2626f26ed95aa02fec5dc5aecb1697bed82e0..c7a13948a39966136cb4eccad71128a45ba88507 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -113,6 +113,8 @@ Core and Builtins
 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.