Ref: astral-sh/ruff#23909 (comment)
Ideally, we could just use Protocol with __call__ to define a callable signature containing various combinations of parameters instead. Once the Protocol relation checks are good, we can remove these variants and define them using protocols instead.
For example, instead of:
from ty_extensions import CallableTypeOf, is_subtype_of, static_assert
def standard_a(a: int) -> None: ...
def positional_b(b: int, /) -> None: ...
# The names are not important in this context
static_assert(is_subtype_of(CallableTypeOf[standard_a], CallableTypeOf[positional_b]))
we can do:
from typing import Protocol
from ty_extensions import CallableTypeOf, is_subtype_of, static_assert
class Standard(Protocol):
def __call__(self, a: int) -> None: ...
class PositionalOnly(Protocol):
def __call__(self, b: int, /) -> None: ...
# The names are not important in this context
static_assert(is_subtype_of(Standard, PositionalOnly))
Ref: astral-sh/ruff#23909 (comment)
Ideally, we could just use
Protocolwith__call__to define a callable signature containing various combinations of parameters instead. Once theProtocolrelation checks are good, we can remove these variants and define them using protocols instead.For example, instead of:
we can do: