-
Notifications
You must be signed in to change notification settings - Fork 125
Description
Summary
The typing spec states:
If the input signature in a function definition includes both a
*args
and**kwargs
parameter and both are typed asAny
(explicitly or implicitly because it has no annotation), a type checker should treat this as the equivalent of...
. Any other parameters in the signature are unaffected and are retained as part of the signature
And we can see that in the conformance test suite, this test asserts that Proto7
should be understood as being assignable to Proto6
: although the signature of Proto7
is less permissive than the signature of Proto6
, Proto6
has a gradual signature due to the presence of *args: Any
and **kwargs: Any
in the signature, so the normal rules do not apply. The definitions of Proto6
and Proto7
in this test are:
from typing import Protocol, Any
class Proto6(Protocol):
def __call__(self, a: int, /, *args: Any, k: str, **kwargs: Any) -> None: ...
class Proto7(Protocol):
def __call__(self, a: float, /, b: int, *, k: str, m: str) -> None: ...
Note that both mypy and pyrefly also appear to fail this test currently; only pyright currently passes this test.
A version of this failing test for ty that doesn't involve protocols would be:
from typing import Any
from ty_extensions import CallableTypeOf, is_assignable_to, static_assert
def f(*args: Any, a: int, **kwargs: Any): ...
def g(fwomp: int, /, a: int, *, bar: str, baz: str): ...
static_assert(is_assignable_to(CallableTypeOf[g], CallableTypeOf[f]))
https://play.ty.dev/4f422ed6-1725-4230-b803-a62325e218f6
Version
No response