Side-effect of `ABC.__subclasshook__` / `_abc_instancecheck` ▶ `isinstance(..., Parent)` calls `__subclasscheck__` of uninvolved Child class -> RecursionError
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug report
Bug description:
I realized there is strange error of __subclasshook__, or possibly _abc_instancecheck which creates a side-effect that __subclasshook__ is called on a Child class that is not even queried.
What is even more strange this error only occurs when the crucial statement B is called in a AB situation, just B or BAB is fine.
# At the end of his snippet are 3 test sets, Only the first causes an error the other 2 are fine.
import sys
sys.setrecursionlimit(59)
from abc import ABC
class Base(ABC): ...
class _ParentCheck(Base):
@classmethod
def __subclasshook__(cls, subclass):
if not issubclass(subclass, Base):
return NotImplemented
if not hasattr(subclass, "f"):
return False
return True
class Parent(Base):
f: int
@classmethod
def construct(cls, foo: int):
class Child(cls, _ParentCheck):
f = foo
return Child
# Test Set 1: Error
assert issubclass(Parent.construct(1), Parent) # Statement A
assert not isinstance(lambda: None, Parent) # Statement B
# Test Set 2: OK
assert not isinstance(lambda: None, Parent) # Statement B
# Test Set 3: OK
assert not isinstance(lambda: None, Parent) # Statement B
assert issubclass(Parent.construct(1), Parent) # Statement A
assert not isinstance(lambda: None, Parent) # Statement B
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, den bereitgestellten Reproducer unter CPython 3.14 auszuführen, wobei der Fokus auf ABC.subclasshook, _abc_instancecheck und der Interaktion zwischen Parent und _ParentCheck liegt. Erledigt ist die Aufgabe, wenn Test Set 1 keinen RecursionError mehr auslöst und Test Sets 2 und 3 weiterhin erfolgreich sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100