[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
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 22/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 1.7k
- Fork
- 167
- Merge trung bình
- 3 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 68
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của oracle/graalpython
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
oracle/graalpython#1105 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
oracle/graalpython#1102 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mmap.mmap.move() is missingCó thể đã có người làm @deronnax đã nhận 3 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
oracle/graalpython#1368 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mmap extended slicing ignores the step; negative steps raise java.lang.IndexOutOfBoundsExceptionĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 64/100
oracle/graalpython#1367 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
oracle/graalpython#1366 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của oracle/graalpython
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug improve content
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
opensafely/documentation#2102 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
difficulty:1 documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
MakazhanAlpamys/Soup#3533 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
onyx-dot-app/onyx#18730 ·
Maintainer thường phản hồi trong vòng 1 ngày