New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-87390: Add tests demonstrating current type variable substitution behaviour #32341
base: main
Are you sure you want to change the base?
Conversation
This reverts commit 526d9e8.
Re @JelleZijlstra's suggestion (if I understood right?) to leave unpacked tuples unsimplified across the board: I just realised this means we might have to ease up on checks for the right number of arguments across the board. For example: tuple[T1, T2][*tuple[int, str]] This should be valid, but I think at the moment it would trigger a I guess easing up on type argument number checks should be fine though? The alternative would be to have some fancy logic that tries to detect how many type arguments something like |
Actually, having thought about it more over the past few days, I don't think leaving unpacked tuples unsimplified in all case will work. For example, if we did: Alias = tuple[T1, bool, T2]
Alias[*tuple[int, str]] # Should be tuple[int, bool, str] There's no way we could properly evaluate the result of that unless we did unpack Having said that, Jelle, I'm still bearing in mind your comment: 'generic[T]', '[*tuple_type[int, ...]]', 'generic[*tuple_type[int, ...]]' # Should be generic[int]?
I do agree that for the particular case of I'll update the tests accordingly. |
Here's a reference of what we currently do and don't allow in terms of type variable substitution in aliases. I've marked the cases that I think the current implementation is incorrect on.
Ideally I'd like to merge this as-is, even with the test cases whose expected results aren't what we think they should be - I think it'll make our job implementing the remaining fixes easier if we can just twiddle one line of an existing test case rather than having to remember to copy-paste the test case that each change fixes.
Some cases I'm unsure about are:
tuple[T][*tuple[int, ...]]
. My understanding is that when it comes totuple[int, ...]
, the current behaviour of type checkers is to "Try to find a way to make it work" - I think this should betuple[int]
?class C(Generic[T1, T2]): ...; C[*tuple[int, ...], *tuple[str, ...]]
. By similar reasoning, this should work - but should it beC[int, int]
,C[int, str]
, orC[str, str]
?@pradeep90 What do you think?
https://bugs.python.org/issue47006