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
importabcfromtypingimportProtocolclassP(Protocol):
@abc.abstractmethoddeff(self) ->None: passclassC(P):
passC() # TypeError: Can't instantiate abstract class C with abstract method f
However, mypy doesn't detect a metaclass conflict here:
fromtypingimportProtocolclassMeta(type): pass# Metaclass conflict at runtime, but no mypy errorclassP(Protocol, metaclass=Meta): pass
At runtime this will generate a metaclass conflict:
Mypy should infer typing._ProtocolMeta as the metaclass of protocol classes. Maybe a custom metaclass should also be rejected, at least if it isn't a subclass of typing._ProtocolMeta.
This is actually more complex than this, since some classes declared as protocols in stubs aren't actually real protocols at runtime: python/typeshed#9058 (comment)
At least outside stubs we can probably infer the metaclass. In stubs we should probably accept ABCMeta as a metaclass for protocols, at least, but for this we'll probably need to fix #13986 first.
Activity
JukkaL commentedon Nov 2, 2022
This is actually more complex than this, since some classes declared as protocols in stubs aren't actually real protocols at runtime: python/typeshed#9058 (comment)
At least outside stubs we can probably infer the metaclass. In stubs we should probably accept
ABCMetaas a metaclass for protocols, at least, but for this we'll probably need to fix #13986 first.