You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In CPython >= 3.11, creating an instance of a Protocol class is seemingly permitted at runtime if an initialiser is declared.
However, mypy still reports that the protocol class cannot be instantiated.
I am not sure if the bug lies with mypy or CPython, but, in this edge case, Protocol behaviour at runtime seems to have diverged from mypy's understanding somewhere between Python 3.10 and 3.11.
PEP 544 (which introduced Protocols to the type system) is clear on this point:
Protocols cannot be instantiated, so there are no values whose runtime type is a protocol.
So I think mypy is correct in reporting this error, at least according to the typing spec. Other type checkers like pyright report the same error here.
Uh oh!
There was an error while loading. Please reload this page.
Bug Report
In CPython >= 3.11, creating an instance of a Protocol class is seemingly permitted at runtime if an initialiser is declared.
However, mypy still reports that the protocol class cannot be instantiated.
I am not sure if the bug lies with mypy or CPython, but, in this edge case, Protocol behaviour at runtime seems to have diverged from mypy's understanding somewhere between Python 3.10 and 3.11.
To Reproduce
Actual Behavior
Your Environment
mypy 1.6.1 (compiled: yes)
mypy.ini
(and other config files): N/AThe text was updated successfully, but these errors were encountered: