summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
authorKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>2021-09-08 15:01:51 (GMT)
committerGitHub <noreply@github.com>2021-09-08 15:01:51 (GMT)
commit99506dcbbe9fb56ceabe55f0a4333e5981b72095 (patch)
treec2aa65826f2dfc4332ed44a3a42bf1ac7e6f361f /Lib/typing.py
parentd9b7d427ebc1ed5cfef3657d1d92c2d80346147f (diff)
downloadcpython-99506dcbbe9fb56ceabe55f0a4333e5981b72095.zip
cpython-99506dcbbe9fb56ceabe55f0a4333e5981b72095.tar.gz
cpython-99506dcbbe9fb56ceabe55f0a4333e5981b72095.tar.bz2
[3.9] bpo-45121: Fix RecursionError when calling Protocol.__init__ from a subclass' __init__ (GH-28206) (GH-28233)
Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 9010775..775f178 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -1085,6 +1085,11 @@ def _no_init_or_replace_init(self, *args, **kwargs):
if cls._is_protocol:
raise TypeError('Protocols cannot be instantiated')
+ # Already using a custom `__init__`. No need to calculate correct
+ # `__init__` to call. This can lead to RecursionError. See bpo-45121.
+ if cls.__init__ is not _no_init_or_replace_init:
+ return
+
# Initially, `__init__` of a protocol subclass is set to `_no_init_or_replace_init`.
# The first instantiation of the subclass will call `_no_init_or_replace_init` which
# searches for a proper new `__init__` in the MRO. The new `__init__`