Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cbbec1c

Browse files
Issue #25718: Fixed copying object with state with boolean value is false.
1 parent 7279bef commit cbbec1c

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

Lib/copy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def _reconstruct(x, info, deep, memo=None):
281281
if n > 2:
282282
state = info[2]
283283
else:
284-
state = {}
284+
state = None
285285
if n > 3:
286286
listiter = info[3]
287287
else:
@@ -295,7 +295,7 @@ def _reconstruct(x, info, deep, memo=None):
295295
y = callable(*args)
296296
memo[id(x)] = y
297297

298-
if state:
298+
if state is not None:
299299
if deep:
300300
state = deepcopy(state, memo)
301301
if hasattr(y, '__setstate__'):

Lib/test/test_copy.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ def __eq__(self, other):
180180
return self.foo == other.foo
181181
x = C(42)
182182
self.assertEqual(copy.copy(x), x)
183+
# State with boolean value is false (issue #25718)
184+
x = C(0.0)
185+
self.assertEqual(copy.copy(x), x)
183186

184187
# The deepcopy() method
185188

@@ -448,6 +451,12 @@ def __eq__(self, other):
448451
self.assertEqual(y, x)
449452
self.assertIsNot(y, x)
450453
self.assertIsNot(y.foo, x.foo)
454+
# State with boolean value is false (issue #25718)
455+
x = C([])
456+
y = copy.deepcopy(x)
457+
self.assertEqual(y, x)
458+
self.assertIsNot(y, x)
459+
self.assertIsNot(y.foo, x.foo)
451460

452461
def test_deepcopy_reflexive_inst(self):
453462
class C:

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ Core and Builtins
113113
Library
114114
-------
115115

116+
- Issue #25718: Fixed copying object with state with boolean value is false.
117+
116118
- Issue #10131: Fixed deep copying of minidom documents. Based on patch
117119
by Marian Ganisin.
118120

0 commit comments

Comments
 (0)