FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-133895: provide C99 Annex F return values for math's functions by skirpichev · Pull Request #135008 · python/cpython · GitHub

Repository navigation

gh-133895: provide C99 Annex F return values for math's functions - #135008

Closed
skirpichev wants to merge 4 commits into
python:mainfrom
skirpichev:math-ValueError/133895
Closed

skirpichev wants to merge 4 commits into
python:mainfrom
skirpichev:math-ValueError/133895

Conversation

skirpichev commented Jun 1, 2025 •
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Member

Now this information is available as the "value" attribute of the ValueError exception object:

>>> import math
>>> try:
...     math.gamma(-0.0)
... except ValueError as exc:
...     print(exc.value)
...
-inf

📚 Documentation preview 📚: https://cpython-previews--135008.org.readthedocs.build/

Now this information is available as the "value" attribute of the
ValueError exception object:

```pycon
>>> import math
>>> try:
...     math.gamma(-0.0)
... except ValueError as exc:
...     print(exc.value)
...
-inf
```

Copy link
Copy Markdown
Member Author

See also #134995

skirpichev changed the title gh-133895: provide C99 Annex F return values for math functions gh-133895: provide C99 Annex F return values for math's functions Jun 1, 2025
Comment thread Doc/whatsnew/3.15.rst Outdated
Comment thread Modules/mathmodule.c
PyObject *value = PyFloat_FromDouble(x);

if (value) {
PyObject_SetAttrString(exc, "value", value);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This call can fail. Should we do something about it? or should we simply ignore the exception? or maybe chain it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

or should we simply ignore the exception?

I don't see better option so far. (Ditto for cmath.)

BTW, maybe I should also drop if (value) { clause.

or maybe chain it?

I doubt it's appropriate here. We don't handle ValueError here. This code just alter the raised exception object.

picnixz Jun 1, 2025 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

BTW, maybe I should also drop if (value) { clause.

I don't think you should, otherwise PyObject_SetAttrString will be called with an exception set (and with a NULL value it's the same as deleting the attribute)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

will be called with an exception set

Why it's bad in this case?

and with a NULL value it's the same as deleting the attribute

But we are already ignore errors from the PyObject_SetAttrString :-)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why it's bad in this case?

Don't we have an assert() somewhere that would fail if the error indicator is set?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I failed to find such case.

Though, we could explicitly call (twice) PyErr_Occurred() in appropriate places.

Looking on other cases of using PyErr_GetRaisedException() - I think that unraisable exceptions should be used here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

See cmath's pr, I did such change: #134995. Does it make sense for you?

Comment thread Modules/mathmodule.c Outdated
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
skirpichev marked this pull request as draft June 2, 2025 10:30
skirpichev closed this Oct 10, 2025
skirpichev deleted the math-ValueError/133895 branch October 10, 2025 04:51
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL