Commit 3660617
committed
gh-154594: Fix copy.deepcopy() re-copying objects whose __deepcopy__ returns None
deepcopy() used None both as the memo dict's "not cached" sentinel and
as a value callers can legitimately store there, so a __deepcopy__ that
returns None was indistinguishable from a cache miss and got invoked
again on every subsequent reference to the same object.
Use a direct memo[d] lookup (matching the existing pattern in
_deepcopy_tuple/_deepcopy_frozendict) instead of memo.get(d, None), so
every return value -- including None -- is memoized correctly. This
also avoids reintroducing the non-immortal-sentinel refcount
contention under free-threading that gh-132657/gh-138429 fixed, since
no sentinel object is used at all.1 parent 20b50f8 commit 3660617
3 files changed
Lines changed: 23 additions & 3 deletions
File tree
- Lib
- test
- Misc/NEWS.d/next/Library
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
126 | | - | |
127 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
128 | 129 | | |
129 | 130 | | |
130 | 131 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
509 | 509 | | |
510 | 510 | | |
511 | 511 | | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
512 | 528 | | |
513 | 529 | | |
514 | 530 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
0 commit comments