Side-effect of `ABC.__subclasshook__` / `_abc_instancecheck` ▶ `isinstance(..., Parent)` calls `__subclasscheck__` of uninvolved Child class -> RecursionError
オープン
まだ誰も着手していません。
extension-modules
stdlib
type-bug
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供された再現プログラムを CPython 3.14 で実行し、ABC.subclasshook、_abc_instancecheck、および Parent と _ParentCheck の相互作用に焦点を当てます。Test Set 1 で RecursionError が発生しなくなり、Test Sets 2 と 3 が引き続き成功すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100