[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 天内回复
还没有人认领这个 Issue。
评估
调研方向
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 小时
- 30 天内合并 PR
- 68
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 天内回复