-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
gh-108511: Add C API functions which do not silently ignore errors #109025
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
gh-108511: Add C API functions which do not silently ignore errors #109025
Conversation
Add the following functions: * PyObject_HasAttrWithError() * PyObject_HasAttrStringWithError() * PyMapping_HasKeyWithError() * PyMapping_HasKeyStringWithError()
|
|
|
|
|
|
|
I wrote a first PR to add PyMapping_HasKeyWithError() and PyMapping_HasKeyStringWithError() functions to pythoncapi-compat: python/pythoncapi-compat#73 |
…ors (pythonGH-109025) Add the following functions: * PyObject_HasAttrWithError() * PyObject_HasAttrStringWithError() * PyMapping_HasKeyWithError() * PyMapping_HasKeyStringWithError()
|
||
Return ``1`` if the mapping object has the key *key* and ``0`` otherwise. | ||
This is equivalent to the Python expression ``key in o``. | ||
On failure, return ``-1``. |
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.
Given the relevance of error handling for these new functions, I think the docs should mention explicitly under which conditions users must expect exceptions.
On failure, return ``-1``. | |
On failure, return ``-1`` with an exception set. |
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.
Sometimes I write "On error, raise an exception and return -1." Even if in C, technically, it's more "setting" an exception, I like to use Python "raise" semantics in C, it's easy for me to map C/Python this way :-)
|
||
Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. | ||
This is equivalent to the Python expression ``hasattr(o, attr_name)``. | ||
On failure, return ``-1``. |
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.
Given the relevance of error handling for these new functions, I think the docs should mention explicitly under which conditions users must expect exceptions.
On failure, return ``-1``. | |
On failure, return ``-1`` with an exception set. |
Add the following functions:
📚 Documentation preview 📚: https://cpython-previews--109025.org.readthedocs.build/