Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
gh-95754: Better AttributeError on partially initialised module#112577
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Objects/moduleobject.c Outdated
@@ -841,11 +841,22 @@ _Py_module_getattro_impl(PyModuleObject *m, PyObject *name, int suppress) | |||
} | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
PyObject_GetAttr()
can set not only AttributeError. If it sets a different error, it should not be overridden by AttributeError.
I suggest to usePyObject_GetOptionalAttr()
.
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.
Why not chain the original error to a new exception (raise from)?
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.
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.
Thank you for the reviews! |
I fixed some errors, please resolve conflicts. |
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.
LGTM.
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>
Uh oh!
There was an error while loading.Please reload this page.
Following in the footsteps of: