Commit 0096a049 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #25718: Fixed copying object with state with boolean value is false.

parent d2d6c8c6
...@@ -281,7 +281,7 @@ def _reconstruct(x, info, deep, memo=None): ...@@ -281,7 +281,7 @@ def _reconstruct(x, info, deep, memo=None):
if n > 2: if n > 2:
state = info[2] state = info[2]
else: else:
state = {} state = None
if n > 3: if n > 3:
listiter = info[3] listiter = info[3]
else: else:
...@@ -295,7 +295,7 @@ def _reconstruct(x, info, deep, memo=None): ...@@ -295,7 +295,7 @@ def _reconstruct(x, info, deep, memo=None):
y = callable(*args) y = callable(*args)
memo[id(x)] = y memo[id(x)] = y
if state: if state is not None:
if deep: if deep:
state = deepcopy(state, memo) state = deepcopy(state, memo)
if hasattr(y, '__setstate__'): if hasattr(y, '__setstate__'):
......
...@@ -180,6 +180,9 @@ class TestCopy(unittest.TestCase): ...@@ -180,6 +180,9 @@ class TestCopy(unittest.TestCase):
return self.foo == other.foo return self.foo == other.foo
x = C(42) x = C(42)
self.assertEqual(copy.copy(x), x) 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 # The deepcopy() method
...@@ -448,6 +451,12 @@ class TestCopy(unittest.TestCase): ...@@ -448,6 +451,12 @@ class TestCopy(unittest.TestCase):
self.assertEqual(y, x) self.assertEqual(y, x)
self.assertIsNot(y, x) self.assertIsNot(y, x)
self.assertIsNot(y.foo, x.foo) 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): def test_deepcopy_reflexive_inst(self):
class C: class C:
......
...@@ -113,6 +113,8 @@ Core and Builtins ...@@ -113,6 +113,8 @@ Core and Builtins
Library Library
------- -------
- Issue #25718: Fixed copying object with state with boolean value is false.
- Issue #10131: Fixed deep copying of minidom documents. Based on patch - Issue #10131: Fixed deep copying of minidom documents. Based on patch
by Marian Ganisin. by Marian Ganisin.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment