-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for variadic type aliases (#15219)
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>
- Loading branch information
1 parent
391ed85
commit 0334ebc
Showing
12 changed files
with
507 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.