Repository navigation
Conversation
complexFromComplexObject, the specialization taken when imag is neither a complex nor a string, called imag's __float__ before it looked at real, so an exception from that conversion replaced the first-argument TypeError and complex(Real(), Imag()) converted imag first. CPython's complex_new_impl checks the type of real, then of imag, and only then converts real followed by imag. The specialization now does the same; the (Object, long/double/PInt) specializations already check real first. Signed-off-by: Jeongseop Lim <jeongseop_lim@korea.ac.kr>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #1225
When
imagis neither acomplexnor a string,complex(real, imag)calledimag.__float__before checking thatrealis a number, so an exception from that call replaced the first-argumentTypeError. CPython'scomplex_new_implchecks the type ofreal, then ofimag, and only then convertsrealfollowed byimag(complexobject.c#L945-L1018).AS-IS
TO-BE
(matching CPython)
Changes
ComplexNewNode.complexFromComplexObjectto raise the first-argument error, then the second-argument error, and only then convertrealandimagin that order. The other(Object, long|double|PInt)specializations already checkrealfirst.test_create_checks_arguments_before_convertingtotests/test_complex.py.Testing
mx python-jvmon linux-aarch64, thenmx graalpytest test_complex.py(11 passed) andtest.test_complexfromlib-python(35 passed, same as master). The new test fails on the unpatched build. Twelvecomplex()call shapes, covering__float__,__index__and__complex__arguments andimag=alone, now print the same as CPython 3.12.13.