GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-95754: Better AttributeError on partially initialised module by hauntsaninja · Pull Request #112577 · python/cpython

Conversation

@hauntsaninja

@hauntsaninja hauntsaninja commented Dec 1, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Following in the footsteps of:

  • bpo-33237: Improve AttributeError message for partially initialized module. #6398
  • bpo-20490: Improve circular import error messaging #15308
  • Issue: Add more specific error message when file has same name as an imported module #95754

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hugovk and yilei reacted with hooray emoji
All reactions
  • 🎉 2 reactions
@hauntsaninja
pythongh-95754: Better AttributeError on partially initialised module
3e339ae
@hauntsaninja
hauntsaninja requested review from brettcannon, ericsnowcurrently, ncoghlan and warsaw as code owners December 1, 2023 08:09
@bedevere-app bedevere-app Bot mentioned this pull request Dec 1, 2023
Add more specific error message when file has same name as an imported module #95754
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Dec 1, 2023
@blurb-it
📜🤖 Added by blurb_it.
7222653
serhiy-storchaka
serhiy-storchaka reviewed Dec 1, 2023
View reviewed changes
Comment thread Objects/moduleobject.c Outdated
if (suppress != 1) {
if (_PyModuleSpec_IsInitializing(spec)) {
PyErr_Format(PyExc_AttributeError,
origin = PyObject_GetAttr(spec, &_Py_ID(origin));

@serhiy-storchaka serhiy-storchaka Dec 1, 2023

Copy link
Copy Markdown
Member

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iritkatriel iritkatriel Dec 1, 2023

Copy link
Copy Markdown
Member

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iritkatriel iritkatriel Dec 1, 2023

Copy link
Copy Markdown
Member

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Objects/moduleobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@hauntsaninja
code review
a1c7198
@hauntsaninja
hauntsaninja requested a review from serhiy-storchaka December 1, 2023 21:51
serhiy-storchaka
serhiy-storchaka reviewed Dec 3, 2023
View reviewed changes
Comment thread Objects/moduleobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@hauntsaninja
return null
3bac475
@hauntsaninja

hauntsaninja commented Dec 4, 2023

Copy link
Copy Markdown
Contributor Author

Thank you for the reviews!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Dec 7, 2023

Copy link
Copy Markdown
Member

I fixed some errors, please resolve conflicts.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hauntsaninja added 2 commits December 18, 2023 00:55
@hauntsaninja
Merge remote-tracking branch 'upstream/main' into gh95754
7ffb4a9
@hauntsaninja
rebase changes
e043b30
@hauntsaninja
hauntsaninja requested a review from serhiy-storchaka December 18, 2023 07:02
serhiy-storchaka
serhiy-storchaka reviewed Dec 18, 2023
View reviewed changes
Comment thread Objects/moduleobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka
Update Objects/moduleobject.c
5e27a8f
serhiy-storchaka
serhiy-storchaka approved these changes Dec 18, 2023
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Dec 18, 2023
@hauntsaninja
hauntsaninja merged commit 61e8184 into python:main Dec 21, 2023
@bedevere-app bedevere-app Bot removed the awaiting merge label Dec 21, 2023
@hauntsaninja
hauntsaninja deleted the gh95754 branch December 21, 2023 21:24
@hugovk

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ryan-duve pushed a commit to ryan-duve/cpython that referenced this pull request Dec 26, 2023
@hauntsaninja @serhiy-storchaka @ryan-duve
pythongh-95754: Better AttributeError on partially initialised module (…
7eadfa9
…python#112577)

Co-authored-by: Serhiy Storchaka <[email protected]>
@hauntsaninja hauntsaninja mentioned this pull request Jan 6, 2024
gh-95754: Better error when script shadows a standard library or third party module #113769
Merged
kulikjak pushed a commit to kulikjak/cpython that referenced this pull request Jan 22, 2024
@hauntsaninja @serhiy-storchaka @kulikjak
pythongh-95754: Better AttributeError on partially initialised module (…
17f31d6
…python#112577)

Co-authored-by: Serhiy Storchaka <[email protected]>
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
@hauntsaninja @serhiy-storchaka @aisk
pythongh-95754: Better AttributeError on partially initialised module (…
4bb2407
…python#112577)

Co-authored-by: Serhiy Storchaka <[email protected]>
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
@hauntsaninja @serhiy-storchaka @Glyphack
pythongh-95754: Better AttributeError on partially initialised module (…
c698237
…python#112577)

Co-authored-by: Serhiy Storchaka <[email protected]>
@hugovk hugovk mentioned this pull request Jun 29, 2025
Getting ImportError and suggestion to rename module for no valid reason #136094
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@iritkatriel iritkatriel iritkatriel left review comments
@serhiy-storchaka serhiy-storchaka serhiy-storchaka approved these changes
@brettcannon brettcannon Awaiting requested review from brettcannon brettcannon is a code owner
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@ncoghlan ncoghlan Awaiting requested review from ncoghlan ncoghlan is a code owner
@warsaw warsaw Awaiting requested review from warsaw warsaw is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@hauntsaninja @serhiy-storchaka @hugovk @iritkatriel
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.