-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugmypy got something wrongmypy got something wrong
Description
from typing import Callable
def as_tuple[*Ts](*args: *Ts) -> tuple[*Ts]: return args
def tuple_identity[*Ts](t: tuple[*Ts]) -> tuple[*Ts]: return t
def tuple_identity2[T: tuple](t: T) -> T: return t
def test_paramspec[**P](
dummy: Callable[P, None], # ensure P is bound
/,
*args: P.args,
**kwargs: P.kwargs,
) -> None:
reveal_type(args) # N: "P.args`-1"
reveal_type( (*args,) ) # N: "builtins.tuple[P.args`-1, ...]"
reveal_type( tuple(args) ) # N: "builtins.tuple[builtins.object, ...]"
reveal_type(as_tuple(*args)) # N: "builtins.tuple[P.args`-1, ...]"
reveal_type(tuple_identity(args)) # N: "builtins.tuple[Never, ...]"
# E: [arg-type]
reveal_type(tuple_identity2(args)) # N: "P.args`-1" ✅
if isinstance(args, tuple):
pass
else:
reveal_type(args) # false negative [warn-unreachable]
Ideally, all the reveal_types
should show the same result (or raise errors if considered misuse of ParamSpec
1), and the else
-branch should trigger an unreachable
warning.
Footnotes
-
For instance,
pyright
saysas_tuple(*args)
is illegal. Code sample in pyright playground ↩
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong