summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-11-30 17:35:40 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2015-11-30 17:35:40 +0200
commitb63015b01a07c535ef4c26fe0bc4c336295dd08e (patch)
treefb928a9e06f9d272f98c5d16dc594332dc8e6621
parent3c49710e9fc383c521817cee3cb5d3695430b7ea (diff)
parentcbbec1c53f4b6fb88b4ae984e69db2d2951cd560 (diff)
downloadcpython-git-b63015b01a07c535ef4c26fe0bc4c336295dd08e.tar.gz
Issue #25718: Fixed copying object with state with boolean value is false.
-rw-r--r--Lib/copy.py4
-rw-r--r--Lib/test/test_copy.py9
-rw-r--r--Misc/NEWS2
3 files changed, 13 insertions, 2 deletions
diff --git a/Lib/copy.py b/Lib/copy.py
index 3a45fdf49b..493c487d8a 100644
--- a/Lib/copy.py
+++ b/Lib/copy.py
@@ -279,7 +279,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:
@@ -293,7 +293,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__'):
diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py
index b9eadddbf2..4107e8afd6 100644
--- a/Lib/test/test_copy.py
+++ b/Lib/test/test_copy.py
@@ -213,6 +213,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
@@ -517,6 +520,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:
diff --git a/Misc/NEWS b/Misc/NEWS
index 899f8dce63..43769c12f5 100644
--- 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 #10131: Fixed deep copying of minidom documents. Based on patch
by Marian Ganisin.