mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[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>
This commit is contained in:
parent
d9b7d427eb
commit
99506dcbbe
3 changed files with 18 additions and 0 deletions
|
@ -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__`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue