-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Support for variadic type aliases #15219
Conversation
for more information, see https://pre-commit.ci
This comment has been minimized.
This comment has been minimized.
Nevermind, it works in Python 3.10.11
from typing import TypeAlias, TypeVar
T = TypeVar("T")
IntTuple: TypeAlias = tuple[int, T]
IntTuple[float]
from typing import TypeAlias
from typing_extensions import TypeVarTuple, Unpack
Ts = TypeVarTuple("Ts")
IntTuple: TypeAlias = tuple[int, Unpack[Ts]]
IntTuple[float]
|
@tmke8 there's an open |
OK, I added handling for few more edge cases for type aliases as per PEP 646. Btw, I noticed that PEP explicitly allows @jhance Is there a chance you can look at this PR? I would prefer if you confirm everything looks OK to you before I merge. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
I am assuming there are no more comments on this PR, if there are no objections I will merge it later today. |
Fixes #15062
Implementing "happy path" took like couple dozen lines, but there are a lot of edge cases, e.g. where we need to fail gracefully. Also of course I checked my implementation (mostly) works for recursive variadic aliases :-) see test.
It looks like several pieces of support for proper variadic types (i.e. non-aliases, instances etc) are still missing, so I tried to fill in something where I needed it for type aliases, but not everywhere, some notable examples:
semanal_typeargs.py
len(type_vars) - 1
type arguments, e.g. if one of them is an unpack.Btw I was thinking about an example below, what should we do in such cases?
Finally, I noticed there is already some code duplication, and I am not improving it. I am open to suggestions on how to reduce the code duplication.