diff options
author | Yurii Karabas <1998uriyyo@gmail.com> | 2021-09-08 10:25:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-08 10:25:09 (GMT) |
commit | c11956a8bddd75f02ccc7b4da7e4d8123e1f3c5f (patch) | |
tree | b3c94d1e1dbfda311a8b94fe5a0918df7ac0a121 /Lib/typing.py | |
parent | d003a5bd2505a7fa04f50504b68ba8fca67349cd (diff) | |
download | cpython-c11956a8bddd75f02ccc7b4da7e4d8123e1f3c5f.zip cpython-c11956a8bddd75f02ccc7b4da7e4d8123e1f3c5f.tar.gz cpython-c11956a8bddd75f02ccc7b4da7e4d8123e1f3c5f.tar.bz2 |
bpo-45121: Fix RecursionError when calling Protocol.__init__ from a subclass' __init__ (GH-28206)
Diffstat (limited to 'Lib/typing.py')
-rw-r--r-- | Lib/typing.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index 892f1b3..e29d699 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1406,6 +1406,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__` |