-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
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
Changes from 17 commits
e134bad
00ce038
168f92a
884da66
58dbac5
07c8250
56e3a49
4e13132
b5a661b
ab5eb8f
c681ce2
82efd1c
c687ff8
310ae51
241576a
fd50ea9
587b3cc
bfb206a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Functions :c:func:`PyDict_GetItem`, :c:func:`PyDict_GetItemString`, | ||
| :c:func:`PyMapping_HasKey`, :c:func:`PyMapping_HasKeyString`, | ||
| :c:func:`PyObject_HasAttr`, :c:func:`PyObject_HasAttrString`, and | ||
| :c:func:`PySys_GetObject`, which clear all errors occurred during calling | ||
| the function, report now them using :func:`sys.unraisablehook`. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2468,31 +2468,71 @@ PyMapping_HasKeyWithError(PyObject *obj, PyObject *key) | |
| } | ||
|
|
||
| int | ||
| PyMapping_HasKeyString(PyObject *o, const char *key) | ||
| PyMapping_HasKeyString(PyObject *obj, const char *key) | ||
| { | ||
| PyObject *v; | ||
|
|
||
| v = PyMapping_GetItemString(o, key); | ||
| if (v) { | ||
| Py_DECREF(v); | ||
| return 1; | ||
| PyObject *value; | ||
| int rc; | ||
| if (obj == NULL) { | ||
| // For backward compatibility. | ||
| // PyMapping_GetOptionalItemString() crashes if obj is NULL. | ||
| null_error(); | ||
| rc = -1; | ||
| } | ||
| PyErr_Clear(); | ||
| return 0; | ||
| else { | ||
| rc = PyMapping_GetOptionalItemString(obj, key, &value); | ||
| } | ||
| if (rc < 0) { | ||
| PyErr_FormatUnraisable( | ||
| "Exception ignored in PyMapping_HasKeyString(); consider using " | ||
| "PyMapping_HasKeyStringWithError(), " | ||
| "PyMapping_GetOptionalItemString() or PyMapping_GetItemString()"); | ||
| return 0; | ||
| } | ||
| // PyMapping_HasKeyString() also clears the error set before it's called | ||
| // if the key is not found. | ||
| if (rc == 0 && PyErr_Occurred()) { | ||
| PyErr_FormatUnraisable( | ||
| "Ignore exception set before calling in PyMapping_HasKeyString(); " | ||
| "consider using PyMapping_HasKeyStringWithError(), " | ||
| "PyMapping_GetOptionalItemString() or PyMapping_GetItemString()"); | ||
|
||
| return 0; | ||
| } | ||
| Py_XDECREF(value); | ||
| return rc; | ||
| } | ||
|
|
||
| int | ||
| PyMapping_HasKey(PyObject *o, PyObject *key) | ||
| PyMapping_HasKey(PyObject *obj, PyObject *key) | ||
| { | ||
| PyObject *v; | ||
|
|
||
| v = PyObject_GetItem(o, key); | ||
| if (v) { | ||
| Py_DECREF(v); | ||
| return 1; | ||
| PyObject *value; | ||
| int rc; | ||
| if (obj == NULL || key == NULL) { | ||
| // For backward compatibility. | ||
| // PyMapping_GetOptionalItem() crashes if any of them is NULL. | ||
| null_error(); | ||
| rc = -1; | ||
| } | ||
| PyErr_Clear(); | ||
| return 0; | ||
| else { | ||
| rc = PyMapping_GetOptionalItem(obj, key, &value); | ||
| } | ||
| if (rc < 0) { | ||
| PyErr_FormatUnraisable( | ||
| "Exception ignored in PyMapping_HasKey(); consider using " | ||
| "PyMapping_HasKeyWithError(), " | ||
| "PyMapping_GetOptionalItem() or PyObject_GetItem()"); | ||
| return 0; | ||
| } | ||
| // PyMapping_HasKey() also clears the error set before it's call | ||
| // if the key is not found. | ||
| if (rc == 0 && PyErr_Occurred()) { | ||
| PyErr_FormatUnraisable( | ||
| "Ignore exception set before calling in PyMapping_HasKey(); " | ||
| "consider using PyMapping_HasKeyWithError(), " | ||
| "PyMapping_GetOptionalItem() or PyObject_GetItem()"); | ||
| return 0; | ||
| } | ||
| Py_XDECREF(value); | ||
| return rc; | ||
| } | ||
|
|
||
| /* This function is quite similar to PySequence_Fast(), but specialized to be | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.