Using ellipsis in a TypeVarTuple #1790
-
I want to have an alias for from typing import TypeVarTuple
_ShapeTypeVar = TypeVarTuple('_ShapeTypeVar')
Shape = tuple[*_ShapeTypeVar]
x: Shape[int, ...] This works fine for all types (i.e. I can use this type like
So, either I am not understanding the typing system correctly, or there is something not quite right. I want to make sure I am not doing it completely wrong, so any guidance would be appreciated. Some things I have tried:
Is this a valid way to create an alias for |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The You can use an unpacked tuple to specialize a class parameterized with a TypeVarTuple, like this: x: Shape[*tuple[int, ...]] For more information, refer to the TypeVarTuple section of the typing spec. |
Beta Was this translation helpful? Give feedback.
The
...
token isn't allowed in the specialization of a class parameterized by a TypeVarTuple. It's allowed only for thetuple
class as discussed here in the typing spec.You can use an unpacked tuple to specialize a class parameterized with a TypeVarTuple, like this:
For more information, refer to the TypeVarTuple section of the typing spec.