Uh oh!
There was an error while loading. Please reload this page.
gh-95754: Better AttributeError on partially initialised module - #112577
Conversation
| if (suppress != 1) { | ||
| if (_PyModuleSpec_IsInitializing(spec)) { | ||
| PyErr_Format(PyExc_AttributeError, | ||
| origin = PyObject_GetAttr(spec, &_Py_ID(origin)); |
There was a problem hiding this comment.
PyObject_GetAttr() can set not only AttributeError. If it sets a different error, it should not be overridden by AttributeError.
I suggest to use PyObject_GetOptionalAttr().
There was a problem hiding this comment.
Why not chain the original error to a new exception (raise from)?
There was a problem hiding this comment.
Or maybe this is a use case for adding a note to the original exception and letting it propagate on (if we don't want to change the type of the exception being raised).
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
hauntsaninja
commented
Dec 4, 2023
Thank you for the reviews! |
serhiy-storchaka
commented
Dec 7, 2023
I fixed some errors, please resolve conflicts. |
Uh oh!
There was an error while loading. Please reload this page.
hugovk
commented
Dec 21, 2023
Would be great to mention this nice quality-of-life improvement with an example in What's New, similar to: https://docs.python.org/3/whatsnew/3.12.html#improved-error-messages |
…python#112577) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…python#112577) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…python#112577) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…python#112577) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Following in the footsteps of: