-
-
Notifications
You must be signed in to change notification settings - Fork 66
Open
Description
Let's say you want to write a variadic function, and you want none of its arguments to be none:
def fn(x, *args):
assert x is not None
for arg in args:
assert arg is not None
# do something fun with x and argsIf you want type-annotate this function:
def fn[T, *Ts](
x: T,
*args: *Ts # or equivalently, args: Unpack[Ts]
):
assert x is not None
for arg in args:
assert arg is not None
# do something fun with x and argsLet's say you want to use a beartype.vale validator to make sure that your values are non-None. This is possible on x:
@beartype
def fn[T, *Ts](
x: Annotated[T, ~IsEqual[None]],
*args: *Ts # or equivalently, args: Unpack[Ts]
):
...But it breaks down on args. First, Annotated[*Ts, ...] is invalid Python annotation, with an error of
TypeError: Annotated[...] should not be used with an unpacked TypeVarTuple
(This happens at definition time for 3.13 and at get_annotations() time for 3.14.)
Second, this isn't supported by beartype:
@beartype
def fn[T, *Ts](
x: Annotated[T, ~IsEqual[None]],
*args: Unpack[Annotated[Ts, ~IsEqual[None]]]
):
...Is it possible for beartype to support this type of validators?
leycec and Glinte
Metadata
Metadata
Assignees
Labels
No labels