*Ts syntax in type comments #1452
-
Is it valid to use the
as if it was
? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Type comments have been deprecated for a long time. They are still (partially) supported by some type checkers for old code that needs to remain compatible with Python 2, but you shouldn't be using them for new code. If you want to use from typing_extensions import Unpack, TypeVarTuple
Ts = TypeVarTuple("Ts")
def f(*args: Unpack[Ts]) -> Unpack[Ts]:
... |
Beta Was this translation helpful? Give feedback.
Type comments have been deprecated for a long time. They are still (partially) supported by some type checkers for old code that needs to remain compatible with Python 2, but you shouldn't be using them for new code.
TypeVarTuple
is a relatively new feature, so I wouldn't expect tools to support this with type comments.If you want to use
TypeVarTuple
with a version of Python prior to 3.11, you can usetyping_extensions.Unpack
.