Skip to content

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

Open
dariushoule wants to merge 1 commit into
python:mainfrom
dariushoule:fix-genericalias-parameter-substitution
Open

gh-155752: Do not crash when GenericAlias parameters change during substitution#155761
dariushoule wants to merge 1 commit into
python:mainfrom
dariushoule:fix-genericalias-parameter-substitution

Conversation

@dariushoule

@dariushoule dariushoule commented Aug 13, 2026

Copy link
Copy Markdown

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
with self.assertRaises(TypeError):
a[int]

# gh-155752: GenericAlias parameters are cached before substitution, so

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.

Can you put the comment inside the test as it is usually the case (but not as a docstring please)

@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

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

Labels

awaiting merge 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

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

3 participants