Skip to content

assignability of class literals or type[] types to a protocol #2815

@carljm

Description

@carljm

This example is adapted from https://typing.python.org/en/latest/spec/protocol.html#type-and-class-objects-vs-protocols

from typing import Any, Protocol

class ProtoA(Protocol):
    def meth(self, x: int, /) -> int: ...
class ProtoB(Protocol):
    def meth(self, obj: Any, x: int, /) -> int: ...

class C:
    def meth(self, x: int, /) -> int: ...

a: ProtoA = C  # should fail
b: ProtoB = C  # should pass
def _(tc: type[C]):
    b2: ProtoB = tc  # should pass

In ty, all three of these assignments currently fail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions