Skip to content

Incomplete assignability implementation between two Callable types where one Callable type has *args: Any, **kwargs: Any #1257

@AlexWaygood

Description

@AlexWaygood

Summary

The typing spec states:

If the input signature in a function definition includes both a *args and **kwargs parameter and both are typed as Any (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

Metadata

Metadata

Assignees

No one assigned

    Labels

    callsIssues relating to call-signature checking and diagnosticstype propertiessubtyping, assignability, equivalence, and more

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions