-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-106672: C API: Report indiscriminately ignored errors #106674
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
Merged
serhiy-storchaka
merged 18 commits into
python:main
from
serhiy-storchaka:capi-write-unraisable-for-ignored-errors
Nov 7, 2023
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e134bad
gh-106672: C API: Report indiscriminately ignored errors
serhiy-storchaka 00ce038
Update output messsages.
serhiy-storchaka 168f92a
Add an entry in What's New.
serhiy-storchaka 884da66
Merge branch 'main' into capi-write-unraisable-for-ignored-errors
serhiy-storchaka 58dbac5
Merge branch 'main' into capi-write-unraisable-for-ignored-errors
serhiy-storchaka 07c8250
Fix smelly symbol.
serhiy-storchaka 56e3a49
Remove PyDict_GetItem(dict, invalid_key) from test_dict_capi().
serhiy-storchaka 4e13132
Merge branch 'main' into capi-write-unraisable-for-ignored-errors
serhiy-storchaka b5a661b
Fix regressions in handling NULLs.
serhiy-storchaka ab5eb8f
Merge branch 'main' into capi-write-unraisable-for-ignored-errors
serhiy-storchaka c681ce2
Merge branch 'main' into capi-write-unraisable-for-ignored-errors
serhiy-storchaka 82efd1c
Fix merging error.
serhiy-storchaka c687ff8
Merge branch 'main' into capi-write-unraisable-for-ignored-errors
serhiy-storchaka 310ae51
Add more suggestions.
serhiy-storchaka 241576a
Improve error messages for ignoring errors set before the calls.
serhiy-storchaka fd50ea9
Apply suggestions from code review
serhiy-storchaka 587b3cc
Address review comments.
serhiy-storchaka bfb206a
Remove non-existing cases.
serhiy-storchaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Address review comments.
- Loading branch information
commit 587b3ccd842317e3d097eb7ce63953b29b94fcb8
There are no files selected for viewing
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Can these 3 functions be called with an exception set? They don't override the exception? That sounds surprising. I would prefer suggesting to not call the function with an exception set. What do you think?
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.
Got catch. Indeed,
PyMapping_GetOptionalItemString()
can only return 0 if no exception is set, so this condition is always false. Also, the alternative functions also can clear exceptions.I think that we should classify the C API by classes:
There may be more classes.
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.
In the general case, to write safe code handling a raised exception, I think the safest option is to keep the exception aside using
PyErr_GetRaisedException()
. Maybe today some functions are perfectly fine and never override the currently raised exception. But what if tomorrow their implementation changes, and they may start to clear the currently raised exception?In Python, in an
except:
block, there is no "currently raised exception" in the C level, even ifsys.exc_info()
returns the exception. The difference betweenPyThreadState.exc_info
andPyThreadState.current_exception
is subtle.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.
This is why it should be clearly documented.
Obviously you can call
PyErr_Occurred()
,PyErr_GetRaisedException()
orPyErr_WriteUnraisable()
when an exception is set.