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

Skip to content

Commit 6115460

Browse files
committed
Make sure that *any* object whose id() is used as a memo key is kept
alive in the memo. This fixes SF bug 592567.
1 parent 547607c commit 6115460

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

Lib/copy.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ def deepcopy(x, memo = None):
185185
else:
186186
y = copierfunction(x, memo)
187187
memo[d] = y
188+
_keep_alive(x, memo) # Make sure x lives at least as long as d
188189
return y
189190

190191
_deepcopy_dispatch = d = {}
@@ -269,7 +270,6 @@ def _deepcopy_inst(x, memo):
269270
return x.__deepcopy__(memo)
270271
if hasattr(x, '__getinitargs__'):
271272
args = x.__getinitargs__()
272-
_keep_alive(args, memo)
273273
args = deepcopy(args, memo)
274274
y = apply(x.__class__, args)
275275
else:
@@ -278,7 +278,6 @@ def _deepcopy_inst(x, memo):
278278
memo[id(x)] = y
279279
if hasattr(x, '__getstate__'):
280280
state = x.__getstate__()
281-
_keep_alive(state, memo)
282281
else:
283282
state = x.__dict__
284283
state = deepcopy(state, memo)

0 commit comments

Comments
 (0)