Skip to content

gh-155752: Do not crash when GenericAlias parameters change during substitution - #155761

Merged
JelleZijlstra merged 2 commits into
python:mainfrom
dariushoule:fix-genericalias-parameter-substitution
Aug 14, 2026
Merged

gh-155752: Do not crash when GenericAlias parameters change during substitution#155761
JelleZijlstra merged 2 commits into
python:mainfrom
dariushoule:fix-genericalias-parameter-substitution

Conversation

@dariushoule

@dariushoule dariushoule commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #155752

_Py_subs_parameters() assumed that every argument with a __typing_subst__ attribute was present in the cached __parameters__ tuple. However, __typing_subst__ can be added to an argument after __parameters__ has been cached, causing the lookup to return -1, which is subsequently looked up.

Check the lookup result before indexing the substitution arguments and raise TypeError when the changed argument is not in __parameters__.

…ing substitution

An alias argument can gain __typing_subst__ after __parameters__ has been cached, including during a preparation or substitution callback. Check that the argument is present before indexing the substitution arguments.
@python-cla-bot

python-cla-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@JelleZijlstra JelleZijlstra added needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Aug 13, 2026
Comment thread Lib/test/test_typing.py Outdated

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comment is just a nitpick btw

@JelleZijlstra
JelleZijlstra merged commit c0006fa into python:main Aug 14, 2026
98 of 100 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @dariushoule for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11, 3.12, 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Aug 14, 2026

Copy link
Copy Markdown

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Aug 14, 2026
@bedevere-app

bedevere-app Bot commented Aug 14, 2026

Copy link
Copy Markdown

GH-155771 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 Aug 14, 2026
@miss-islington-app

Copy link
Copy Markdown

Sorry, @dariushoule and @JelleZijlstra, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker c0006faf4f48f01126a8a0752da8f159142e410d 3.12

@bedevere-app

bedevere-app Bot commented Aug 14, 2026

Copy link
Copy Markdown

GH-155772 is a backport of this pull request to the 3.13 branch.

@miss-islington-app

Copy link
Copy Markdown

Sorry, @dariushoule and @JelleZijlstra, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker c0006faf4f48f01126a8a0752da8f159142e410d 3.11

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Aug 14, 2026
@miss-islington-app

Copy link
Copy Markdown

Sorry, @dariushoule and @JelleZijlstra, I could not cleanly backport this to 3.10 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker c0006faf4f48f01126a8a0752da8f159142e410d 3.10

@BHUVANSH855

Copy link
Copy Markdown
Contributor

@JelleZijlstra @picnixz
can I work on the backport PRs ?

hugovk pushed a commit that referenced this pull request Aug 14, 2026
…ring substitution (GH-155761) (#155770)

gh-155752: Do not crash when GenericAlias parameters change during substitution (GH-155761)

An alias argument can gain __typing_subst__ after __parameters__ has been cached, including during a preparation or substitution callback. Check that the argument is present before indexing the substitution arguments.
(cherry picked from commit c0006fa)

Co-authored-by: Darius Houle <dariushoule@gmail.com>
mbeijen pushed a commit to mbeijen/cpython that referenced this pull request Aug 14, 2026
…ing substitution (python#155761)

An alias argument can gain __typing_subst__ after __parameters__ has been cached, including during a preparation or substitution callback. Check that the argument is present before indexing the substitution arguments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GenericAlias crashes when an argument gains __typing_subst__ after parameters are cached

4 participants