Disallow instantiating a Protocol class · Issue #12261 · python/mypy (original) (raw)
The following gives an error in Pyright and I think it should give an error in MyPy as well:
from typing import Protocol
class Foo(Protocol): ...
Foo()
https://mypy-play.net/?mypy=latest&python=3.10&gist=f4ca0ee490d9e8b3a117ee785b7bdaf6
I think that even if the protocol class implements an __init__
method, this should still be disallowed:
from typing import Protocol
class Foo(Protocol): def init(self) -> None: pass
Foo() # disallowed
class ConcreteFoo(Foo): ...
ConcreteFoo() # allowed