gh-155752: Do not crash when GenericAlias parameters change during substitution - #155761
Open
dariushoule wants to merge 1 commit into
Open
gh-155752: Do not crash when GenericAlias parameters change during substitution#155761dariushoule wants to merge 1 commit into
dariushoule wants to merge 1 commit into
Conversation
…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.
dariushoule
requested review from
AlexWaygood and
JelleZijlstra
as code owners
August 13, 2026 21:00
JelleZijlstra
approved these changes
Aug 13, 2026
picnixz
reviewed
Aug 13, 2026
| with self.assertRaises(TypeError): | ||
| a[int] | ||
|
|
||
| # gh-155752: GenericAlias parameters are cached before substitution, so |
Member
There was a problem hiding this comment.
Can you put the comment inside the test as it is usually the case (but not as a docstring please)
picnixz
approved these changes
Aug 13, 2026
picnixz
left a comment
Member
There was a problem hiding this comment.
My comment is just a nitpick btw
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
TypeErrorwhen the changed argument is not in__parameters__.