FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-95754: Better AttributeError on partially initialised module by hauntsaninja · Pull Request #112577 · python/cpython · GitHub

Repository navigation

gh-95754: Better AttributeError on partially initialised module - #112577

Merged
hauntsaninja merged 7 commits into
python:mainfrom
hauntsaninja:gh95754
Dec 21, 2023
Merged

hauntsaninja merged 7 commits into
python:mainfrom
hauntsaninja:gh95754

Conversation

hauntsaninja commented Dec 1, 2023 •
edited
Loading

Copy link
Copy Markdown
Contributor

Comment thread Objects/moduleobject.c Outdated
if (suppress != 1) {
if (_PyModuleSpec_IsInitializing(spec)) {
PyErr_Format(PyExc_AttributeError,
origin = PyObject_GetAttr(spec, &_Py_ID(origin));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why not chain the original error to a new exception (raise from)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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).

Comment thread Objects/moduleobject.c Outdated
Comment thread Objects/moduleobject.c

Copy link
Copy Markdown
Contributor Author

Thank you for the reviews!

Copy link
Copy Markdown
Member

I fixed some errors, please resolve conflicts.

Comment thread Objects/moduleobject.c Outdated

serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM.

hauntsaninja merged commit 61e8184 into python:main Dec 21, 2023
hauntsaninja deleted the gh95754 branch December 21, 2023 21:24

hugovk commented Dec 21, 2023

Copy link
Copy Markdown
Member

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

ryan-duve pushed a commit to ryan-duve/cpython that referenced this pull request Dec 26, 2023
kulikjak pushed a commit to kulikjak/cpython that referenced this pull request Jan 22, 2024
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL