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

Skip to content

Commit b63015b

Browse files
Issue #25718: Fixed copying object with state with boolean value is false.
2 parents 3c49710 + cbbec1c commit b63015b

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
@@ -279,7 +279,7 @@ def _reconstruct(x, info, deep, memo=None):
279279
if n > 2:
280280
state = info[2]
281281
else:
282-
state = {}
282+
state = None
283283
if n > 3:
284284
listiter = info[3]
285285
else:
@@ -293,7 +293,7 @@ def _reconstruct(x, info, deep, memo=None):
293293
y = callable(*args)
294294
memo[id(x)] = y
295295

296-
if state:
296+
if state is not None:
297297
if deep:
298298
state = deepcopy(state, memo)
299299
if hasattr(y, '__setstate__'):

Lib/test/test_copy.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ def __eq__(self, other):
213213
return self.foo == other.foo
214214
x = C(42)
215215
self.assertEqual(copy.copy(x), x)
216+
# State with boolean value is false (issue #25718)
217+
x = C(0.0)
218+
self.assertEqual(copy.copy(x), x)
216219

217220
# The deepcopy() method
218221

@@ -517,6 +520,12 @@ def __eq__(self, other):
517520
self.assertEqual(y, x)
518521
self.assertIsNot(y, x)
519522
self.assertIsNot(y.foo, x.foo)
523+
# State with boolean value is false (issue #25718)
524+
x = C([])
525+
y = copy.deepcopy(x)
526+
self.assertEqual(y, x)
527+
self.assertIsNot(y, x)
528+
self.assertIsNot(y.foo, x.foo)
520529

521530
def test_deepcopy_reflexive_inst(self):
522531
class C:

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Core and Builtins
2020
Library
2121
-------
2222

23+
- Issue #25718: Fixed copying object with state with boolean value is false.
24+
2325
- Issue #10131: Fixed deep copying of minidom documents. Based on patch
2426
by Marian Ganisin.
2527

0 commit comments

Comments
 (0)