Skip to content

gh-154594: Fix deepcopy memo lookup when __deepcopy__ returns None#154595

Open
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:fix-deepcopy-none-sentinel
Open

gh-154594: Fix deepcopy memo lookup when __deepcopy__ returns None#154595
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:fix-deepcopy-none-sentinel

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

PR #138429 (gh-132657) replaced the memo-miss sentinel from _nil = [] to None for free-threading performance. But None is a valid deepcopy result, so memo.get(d, None) can't distinguish "not found" from "found None". This skips memoization for None-valued results, causing redundant __deepcopy__ calls.

Fix: use a private _MEMO_MISS = object() sentinel. Immortalized objects have no refcount contention, so the FT benefit is preserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant