Skip to content

Possibly remove *CallableTypeOf, into_*_callable from ty_extension #3030

@dhruvmanila

Description

@dhruvmanila

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))

Metadata

Metadata

Assignees

No one assigned

    Labels

    testingRelated to testing ty itselfwishNot on the current roadmap; maybe in the future

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions