Skip to content

gh-159739: Do not intern complex subclasses in code constants - #159980

Merged
JelleZijlstra merged 2 commits into
python:mainfrom
jelle-openai:jelle/codex/gh-159739-complex-subclass-interning
Oct 22, 2026
Merged

JelleZijlstra merged 2 commits into
python:mainfrom
jelle-openai:jelle/codex/gh-159739-complex-subclass-interning

Conversation

@jelle-openai

@jelle-openai jelle-openai commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Do not intern complex subclasses in code constants. On free-threaded builds, the code-constant interning check accepts complex subclasses instead of only exact complex objects. An instance supplied through code.replace(co_consts=...) can therefore run a user-defined __hash__ during code-object creation and become immortal, unexpectedly retaining the instance and anything it references.

Backport to 3.15 and 3.14.

@JelleZijlstra JelleZijlstra added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 20, 2026
Comment thread Lib/test/test_code.py Outdated
@JelleZijlstra
JelleZijlstra enabled auto-merge (squash) October 22, 2026 14:39
@JelleZijlstra
JelleZijlstra merged commit e67334a into python:main Oct 22, 2026
60 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @jelle-openai for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Oct 22, 2026

Copy link
Copy Markdown

GH-160249 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 22, 2026
@bedevere-app

bedevere-app Bot commented Oct 22, 2026

Copy link
Copy Markdown

GH-160250 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 22, 2026
JelleZijlstra pushed a commit that referenced this pull request Oct 22, 2026
…H-159980) (#160249)

gh-159739: Do not intern complex subclasses in code constants (GH-159980)
(cherry picked from commit e67334a)

Co-authored-by: Jelle Zijlstra <jelle@openai.com>
JelleZijlstra pushed a commit that referenced this pull request Oct 22, 2026
…H-159980) (#160250)

(cherry picked from commit e67334a)

Co-authored-by: Jelle Zijlstra <jelle@openai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants