gh-87390: Add tests demonstrating current type variable substitution behaviour by mrahtz · Pull Request #32341 · python/cpython (original) (raw)
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 *tuple[int, str]
. I've added another test case for this scenario.
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'd rather leave this as is. If we simplify it, we make it impossible for runtime introspection to even tell the difference.
I do agree that for the particular case of *tuple[int, ...]
we should leave it unsimplified. I think the only alias involving *tuple[int, ...]
that should be valid at runtime for now is generic[*Ts][*tuple[int, ...]]
.
I'll update the tests accordingly.