[Bug]: `complex(real, imag)` converts `imag` before rejecting a non-number `real`
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Đọc ComplexBuiltins.java, đặc biệt là complexFromComplexObject quanh các dòng được trích dẫn và complexFromComplexLong để xem các bước kiểm tra đối số hiện có. Tái hiện lỗi bằng ví dụ Python được cung cấp, sau đó chạy các bài kiểm thử liên quan đến hàm tạo complex. Hoàn tất khi real không hợp lệ bị từ chối trước khi chuyển đổi imag, đúng với lỗi và thứ tự chuyển đổi của CPython.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
When imag is a user object, complex(real, imag) calls its __float__ or __index__ before checking that real is a number. An exception from that conversion replaces the TypeError CPython raises for the first argument, and CPython never calls the method at all.
Operating system
Linux
CPU architecture
ARM64
GraalPy version
25.0.2 (Python 3.12.8); also reproduced on 25.4.4.1.1 (Python 3.13.14)
JDK version
No response
Context configuration
No response
Steps to reproduce
class RaisingFloat:
def __float__(self):
raise Exception()
complex({}, RaisingFloat())
GraalPy 25.0.2 raises the Exception from RaisingFloat.__float__:
Exception
Expected behavior
CPython 3.12.13 (same on 3.13.16):
TypeError: complex() first argument must be a string or a number, not 'dict'
Stack trace
Additional context
The conversion order is reversed too: with both arguments defining a raising __float__, GraalPy calls only imag.__float__ and CPython calls only real.__float__. When imag is an int or float, another specialization checks real first, so complex({1: 2}, 0) already matches CPython.
Root Cause
ComplexNewNode.complexFromComplexObject, taken when imag is neither complex nor a string, converts two at ComplexBuiltins.java#L621-L622 and only then checks one (#L623-L630). CPython's complex_new_impl checks the type of real and then imag (complexobject.c#L945-L972) before converting either (#L995, #L1018).
Fix Suggestion
Reorder complexFromComplexObject to raise the first-argument error, then the second-argument error, and only then convert one and two, as complexFromComplexLong (#L532-L539) already checks one first.
- Ngôn ngữ chính
- Python
- Star
- 1.7k
- Fork
- 163
- Merge trung bình
- 8 giờ 15 phút
- Pull request đã merge (30 ngày)
- 49
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]: `reversed()` on a dict or dict view returns the forward iterator type instead of `dict_reverse*iterator`Có thể đã có người làm @jseop-lim đã nhận 2 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
oracle/graalpython#1226 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: sys.flags.debug is 1 whenever optimization is offCó thể đã có người làm @hippi345 đã nhận 5 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
oracle/graalpython#1213 ·
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 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
-
[Bug]: `compile()` with unrecognised flags raises a `ValueError` whose message crashes with `NullPointerException`Có thể đã có người làm @jseop-lim đã nhận 2 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
oracle/graalpython#1231 ·
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ự
-
follow-up
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Download helper still uses huggingface_hub arguments removed in 1.0: USE_SYMLINKS is silently ignored and every download ends with a WinError 3 lineCó thể đã có người làm @li-lizhe đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
IPv6 node addresses produce an invalid request URLCó thể đã có người làm @RaphaelFakhri đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
typesense/typesense-python#154 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
elastic/elasticsearch-py#3592 ·
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 77/100
developmentseed/titiler-cmr#250 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày