summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index e492bd2..6f884e1 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -1379,8 +1379,7 @@ def _is_callable_members_only(cls):
def _no_init(self, *args, **kwargs):
- if type(self)._is_protocol:
- raise TypeError('Protocols cannot be instantiated')
+ raise TypeError('Protocols cannot be instantiated')
def _caller(depth=1, default='__main__'):
try:
@@ -1523,6 +1522,15 @@ class Protocol(Generic, metaclass=_ProtocolMeta):
# We have nothing more to do for non-protocols...
if not cls._is_protocol:
+ if cls.__init__ == _no_init:
+ for base in cls.__mro__:
+ init = base.__dict__.get('__init__', _no_init)
+ if init != _no_init:
+ cls.__init__ = init
+ break
+ else:
+ # should not happen
+ cls.__init__ = object.__init__
return
# ... otherwise check consistency of bases, and prohibit instantiation.