[Bug]: After `obj.__class__ = C`, calling `C(arg)` for a class with a metaclass such as `ABCMeta` fails with `object.__new__() takes exactly one argument` from the third call on
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 22/100
調査の方向性
The failure sits in how GraalPy resolves __new__ after __class__ is reassigned, so the search starts at the __class__ setter and the type call path for classes with a metaclass. Run the reproduction script from the issue; the fault appears from the third call at the cls(*args) line. Done when all four rounds print C and the metaclass-as-type-subclass variant also passes.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
C inherits a __new__ that accepts extra arguments and has a metaclass (here abc.ABCMeta). Once some object's __class__ has been set to C, a call site that has already called both the base class and C starts raising TypeError: object.__new__() takes exactly one argument (the type to instantiate) for C(arg), as if C had no __new__ of its own. The first two rounds work; every later round fails. CPython constructs the object every time.
Operating system
macOS
CPU architecture
ARM64
GraalPy version
25.6.5.1 (Python 3.13.14), community build from the GitHub release. Same on master 2e574af1d8.
JDK version
No response
Context configuration
No response
Steps to reproduce
import abc
class Base:
def __new__(cls, *args):
return object.__new__(cls)
def __init__(self, *args):
pass
class C(Base, metaclass=abc.ABCMeta):
pass
def make(cls, *args):
return cls(*args)
for i in range(4):
try:
make(Base, "a")
Base().__class__ = C
print(i, type(make(C, "b")).__name__)
except TypeError as e:
print(i, "TypeError:", e)
GraalPy:
0 C
1 C
2 TypeError: object.__new__() takes exactly one argument (the type to instantiate)
3 TypeError: object.__new__() takes exactly one argument (the type to instantiate)
Expected behavior
CPython 3.13.18:
0 C
1 C
2 C
3 C
Additional context
All three ingredients are needed on GraalPy:
- Without the
__class__assignment, all four rounds printC. - With
class C(Base)(metaclasstype), all four rounds printC. Anytypesubclass as metaclass fails, not onlyABCMeta. - Without the
make(Base, "a")call, so that the call site only seesC, all four rounds printC.
The same happens when the call is type(self)(*args) inside a method and self is the object whose __class__ was assigned. The traceback ends at the cls(*args) call, not inside Base.__new__, so the __new__ that gets called is object.__new__ itself.
- 主要言語
- Python
- スター
- 1.7k
- フォーク
- 167
- 平均マージ
- 3日 11時間
- マージ済み PR(30日)
- 68
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
oracle/graalpython のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
oracle/graalpython#1105 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
oracle/graalpython#1102 ·
メンテナーはふだん 1 日以内に返信
-
mmap.mmap.move() is missing対応中かも @deronnax が 3 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 62/100
oracle/graalpython#1368 ·
メンテナーはふだん 1 日以内に返信
-
mmap extended slicing ignores the step; negative steps raise java.lang.IndexOutOfBoundsExceptionオープン
難易度 3/5 1〜2日 初心者へのやさしさ 64/100
oracle/graalpython#1367 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 22/100
oracle/graalpython#1366 ·
メンテナーはふだん 1 日以内に返信
oracle/graalpython の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
bug improve content
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
opensafely/documentation#2102 ·
メンテナーはふだん 1 日以内に返信
-
difficulty:1 documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
MakazhanAlpamys/Soup#3533 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
onyx-dot-app/onyx#18730 ·
メンテナーはふだん 1 日以内に返信