Skip to content

Commit

Permalink
Issue #25718: Fixed copying object with state with boolean value is f…
Browse files Browse the repository at this point in the history
…alse.
  • Loading branch information
serhiy-storchaka committed Nov 30, 2015
2 parents 3c49710 + cbbec1c commit b63015b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Lib/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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__'):
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ def __eq__(self, other):
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

Expand Down Expand Up @@ -517,6 +520,12 @@ def __eq__(self, other):
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:
Expand Down
2 changes: 2 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit b63015b

Please sign in to comment.