You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
* Type variable bound checks for instances are still broken, see TODO
item in `semanal_typeargs.py`
* I think type argument count check is still broken for instances (I
think I fixed it for type aliases), there can be fewer than
`len(type_vars) - 1` type arguments, e.g. if one of them is an unpack.
* We should only prohibit multiple *variadic* unpacks in a type list,
multiple fixed length unpacks are fine (I think I fixed this both for
aliases and instances)
Btw I was thinking about an example below, what should we do in such
cases?
```python
from typing import Tuple, TypeVar
from typing_extensions import TypeVarTuple, Unpack
T = TypeVar("T")
S = TypeVar("S")
Ts = TypeVarTuple("Ts")
Alias = Tuple[T, S, Unpack[Ts], S]
def foo(*x: Unpack[Ts]) -> None:
y: Alias[Unpack[Ts], int, str]
reveal_type(y) # <-- what is this type?
# Ts = () => Tuple[int, str, str]
# Ts = (bool) => Tuple[bool, int, str, int]
# Ts = (bool, float) => Tuple[bool, float, int, str, float]
```
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.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
0 commit comments