-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-133895: provide C99 Annex G return values for cmath's functions #134995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Now this information is available as the "value" attribute of the ValueError exception object: ```pycon >>> import cmath >>> try: ... cmath.log(complex(-0.0, 0)) ... except ValueError as exc: ... print(exc.value) ... (-inf+3.141592653589793j) ``` Also uses the AC magic for return value of the cmath.rect().
CC @abhigyan631 as author of #133923 |
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Misc/NEWS.d/next/Library/2025-06-01-10-38-00.gh-issue-133895.0X7c-V.rst
Outdated
Show resolved
Hide resolved
Misc/NEWS.d/next/Library/2025-06-01-10-38-00.gh-issue-133895.0X7c-V.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
I changed exception handling along the way, suggested by @serhiy-storchaka. I hope I did that right. If so, I can adjust the math's pr. Now we add |
exc_string = PyUnicode_FromString("math range error"); | ||
} | ||
if (!exc_string) { | ||
Py_DECREF(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very fond of stealing a reference here. Maybe we can just return -1 and make the DECREF in the caller?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we just have to put Py_DECREF(value)
unconditionally after every set_cmath_error(value) call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'll be a bit cleaner (I find following code that doesn't steal references much easier, even if it sometimes leads to more lines). But since you're mainly the one maintaining math/cmath, it's up to you though. I'd appreciate a small comment in the function though to know that 'value' is stolen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'll be a bit cleaner
Maybe. Lets other reviewers decide. Meanwhile, I left a comment.
you're mainly the one maintaining math/cmath
No :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, you're someone with many contributions in this module!
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Now this information is available as the "value" attribute of raised exception objects, for example:
Also uses the AC magic for return value of the cmath.rect().
📚 Documentation preview 📚: https://cpython-previews--134995.org.readthedocs.build/