summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/copy.py4
-rw-r--r--Lib/test/test_copy.py9
2 files changed, 11 insertions, 2 deletions
diff --git a/Lib/copy.py b/Lib/copy.py
index bb8840ed54..f0fb443777 100644
--- a/Lib/copy.py
+++ b/Lib/copy.py
@@ -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__'):
diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py
index eb8d18cf0b..0c5354c65c 100644
--- a/Lib/test/test_copy.py
+++ b/Lib/test/test_copy.py
@@ -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: