python / typing

Python static typing home. Hosts the documentation and a user help forum.
https://typing.readthedocs.io/
Other
1.6k stars 235 forks source link

[spec] a protocol type should be assignable to object? #1780

Open carljm opened 4 months ago

carljm commented 4 months ago

See https://github.com/python/typing/pull/1743#discussion_r1640641003

JelleZijlstra commented 4 months ago

Mypy, pyre, and pyright all already allow protocol types to be assigned to object. Test program:

from typing import Protocol

def f(x: object) -> None:
    pass

def g(x: int) -> None:
    pass

class X(Protocol):
    foo: int

def h(x: X) -> None:
    f(x)  # OK: protocol is assignable to object
    g(x)  # E: protocol is not assignable to int