Incorrect example of Protocol type check in documentation
topic: documentation
<!-- Please describe the problem or your idea or suggestion below. Please include the URL of the page this issue is about, if applicable. -->
On the page "Protocols — typing documentation" in section ["`type[]` and class objects vs protocols"](https://typing.python.org/en/latest/spec/protocol.html#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:
```python
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:
```python
a: ProtoA = C() # OK
b: ProtoB = C() # Error
```
关闭于 2026-02-14 5 条评论