Skip to content

Incorrect example of Protocol type check in documentation #2176

@e1turin

Description

@e1turin

On the page "Protocols — typing documentation" in section "type[] and class objects vs protocols" is given wrong example: instead of class instances are given class references. Even more, error and success cases are mismatched:

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  # Type check error, signatures don't match!
b: ProtoB = C  # OK

Should be this:

a: ProtoA = C()  # OK
b: ProtoB = C()  # Error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions