]> 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 c227a2e5c7cb740230652b5b871c74367b6b370d..daf81a3ff83bca923596fe95b6f6ef655be612a4 100644 (file)
@@ -315,7 +315,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:
@@ -329,7 +329,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 6b64f10112e1e2a49726aafaaffc4688014dfbaf..aefc433e825ac8c8d1a70533547f9ace7736fcbb 100644 (file)
@@ -165,6 +165,9 @@ class TestCopy(unittest.TestCase):
                 return cmp(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
 
@@ -395,6 +398,12 @@ class TestCopy(unittest.TestCase):
         x = C([42])
         y = copy.deepcopy(x)
         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.assertTrue(y is not x)
         self.assertTrue(y.foo is not x.foo)
 
index 4a32e47272207d0ac88a0cdc704772b765c59e58..716be231485dc2e871230065366f470b1b2de6e3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -20,6 +20,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #25718: Fixed copying object with state with boolean value is false.
+
 - Issue #25742: :func:`locale.setlocale` now accepts a Unicode string for
   its second parameter.