-
-
Notifications
You must be signed in to change notification settings - Fork 32k
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. |
The simulator needs to be tested with Python 3.12 - it presently does not fully work on Python 3.13 due to the change in behaviour for `PyObject_HasAttr()` to no longer silently ignore all errors as it did previously. Numba's typecode fingerprinting calls something which is approximately `PyObject_HasAttr("_numba_type_")` on NumPy arrays during some execution paths of the simulator, which causes NumPy to raise `ValueError("no field of name _numba_type_")`. Since Python 3.13 this causes masses of warnings to be raised that flood the output. References: - Python 3.12 `PyObject_HasAttr()`: https://docs.python.org/3.12/c-api/object.html#c.PyObject_HasAttr > "Exceptions that occur when this calls __getattr__() and > __getattribute__() methods are silently ignored." - Python 3.13 `PyObject_HasAttr()`: https://docs.python.org/3.13/c-api/object.html#c.PyObject_HasAttr > "Exceptions that occur when this calls __getattr__() and > __getattribute__() methods aren’t propagated, but instead given to > sys.unraisablehook(). For proper error handling, use > PyObject_HasAttrWithError(), ..." - CPython commit adding the recommended functions: python/cpython#109025 - CPython issue: python/cpython#108511
The simulator needs to be tested with Python 3.12 - it presently does not fully work on Python 3.13 due to the change in behaviour for `PyObject_HasAttr()` to no longer silently ignore all errors as it did previously. Numba's typecode fingerprinting calls something which is approximately `PyObject_HasAttr("_numba_type_")` on NumPy arrays during some execution paths of the simulator, which causes NumPy to raise `ValueError("no field of name _numba_type_")`. Since Python 3.13 this causes masses of warnings to be raised that flood the output. References: - Python 3.12 `PyObject_HasAttr()`: https://docs.python.org/3.12/c-api/object.html#c.PyObject_HasAttr > "Exceptions that occur when this calls __getattr__() and > __getattribute__() methods are silently ignored." - Python 3.13 `PyObject_HasAttr()`: https://docs.python.org/3.13/c-api/object.html#c.PyObject_HasAttr > "Exceptions that occur when this calls __getattr__() and > __getattribute__() methods aren’t propagated, but instead given to > sys.unraisablehook(). For proper error handling, use > PyObject_HasAttrWithError(), ..." - CPython commit adding the recommended functions: python/cpython#109025 - CPython issue: python/cpython#108511
The simulator needs to be tested with Python 3.12 - it presently does not fully work on Python 3.13 due to the change in behaviour for `PyObject_HasAttr()` to no longer silently ignore all errors as it did previously. Numba's typecode fingerprinting calls something which is approximately `PyObject_HasAttr("_numba_type_")` on NumPy arrays during some execution paths of the simulator, which causes NumPy to raise `ValueError("no field of name _numba_type_")`. Since Python 3.13 this causes masses of warnings to be raised that flood the output. References: - Python 3.12 `PyObject_HasAttr()`: https://docs.python.org/3.12/c-api/object.html#c.PyObject_HasAttr > "Exceptions that occur when this calls __getattr__() and > __getattribute__() methods are silently ignored." - Python 3.13 `PyObject_HasAttr()`: https://docs.python.org/3.13/c-api/object.html#c.PyObject_HasAttr > "Exceptions that occur when this calls __getattr__() and > __getattribute__() methods aren’t propagated, but instead given to > sys.unraisablehook(). For proper error handling, use > PyObject_HasAttrWithError(), ..." - CPython commit adding the recommended functions: python/cpython#109025 - CPython issue: python/cpython#108511
The simulator needs to be tested with Python 3.12 - it presently does not fully work on Python 3.13 due to the change in behaviour for `PyObject_HasAttr()` to no longer silently ignore all errors as it did previously. Numba's typecode fingerprinting calls something which is approximately `PyObject_HasAttr("_numba_type_")` on NumPy arrays during some execution paths of the simulator, which causes NumPy to raise `ValueError("no field of name _numba_type_")`. Since Python 3.13 this causes masses of warnings to be raised that flood the output. References: - Python 3.12 `PyObject_HasAttr()`: https://docs.python.org/3.12/c-api/object.html#c.PyObject_HasAttr > "Exceptions that occur when this calls __getattr__() and > __getattribute__() methods are silently ignored." - Python 3.13 `PyObject_HasAttr()`: https://docs.python.org/3.13/c-api/object.html#c.PyObject_HasAttr > "Exceptions that occur when this calls __getattr__() and > __getattribute__() methods aren’t propagated, but instead given to > sys.unraisablehook(). For proper error handling, use > PyObject_HasAttrWithError(), ..." - CPython commit adding the recommended functions: python/cpython#109025 - CPython issue: python/cpython#108511
The simulator needs to be tested with Python 3.12 - it presently does not fully work on Python 3.13 due to the change in behaviour for `PyObject_HasAttr()` to no longer silently ignore all errors as it did previously. Numba's typecode fingerprinting calls something which is approximately `PyObject_HasAttr("_numba_type_")` on NumPy arrays during some execution paths of the simulator, which causes NumPy to raise `ValueError("no field of name _numba_type_")`. Since Python 3.13 this causes masses of warnings to be raised that flood the output. References: - Python 3.12 `PyObject_HasAttr()`: https://docs.python.org/3.12/c-api/object.html#c.PyObject_HasAttr > "Exceptions that occur when this calls __getattr__() and > __getattribute__() methods are silently ignored." - Python 3.13 `PyObject_HasAttr()`: https://docs.python.org/3.13/c-api/object.html#c.PyObject_HasAttr > "Exceptions that occur when this calls __getattr__() and > __getattribute__() methods aren’t propagated, but instead given to > sys.unraisablehook(). For proper error handling, use > PyObject_HasAttrWithError(), ..." - CPython commit adding the recommended functions: python/cpython#109025 - CPython issue: python/cpython#108511
Add the following functions:
📚 Documentation preview 📚: https://cpython-previews--109025.org.readthedocs.build/