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 — [3.15] gh-155194: Fix not raising on non-module import by DinoV · Pull Request #155188 · python/cpython

Conversation

@DinoV

@DinoV DinoV commented Aug 4, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

As initially reported here: https://discuss.python.org/t/sys-lazy-modules-clarification/108385

lazy import math.pi has divergent behavior from import math.pi. Currently we allow this to work and just give you the math module. Instead we should raise ModuleNotFoundError because math.pi is not a module.

This would be a breaking change in the future so starting w/ fixing it in 3.15 because fixing it only in later versions would probably be bad.

Sorry, something went wrong.

Uh oh!

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

All reactions
@DinoV
Fix not raising on non-module import
69e82f2
@DinoV DinoV changed the title Fix not raising on non-module import gh-155194: Fix not raising on non-module import Aug 4, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Aug 4, 2026
lazy imports allow lazy import math.pi #155194
Closed
@DinoV DinoV added the skip news label Aug 4, 2026
@DinoV DinoV changed the title gh-155194: Fix not raising on non-module import [3.15] gh-155194: Fix not raising on non-module import Aug 4, 2026
@DinoV
DinoV requested a review from hugovk August 4, 2026 21:22
@DinoV
Fix traceback tests
7063fa2
@DinoV
DinoV force-pushed the lazy_fixes branch from 273069d to 7063fa2 Compare August 4, 2026 21:41
@DinoV
DinoV marked this pull request as ready for review August 4, 2026 22:49
@DinoV
DinoV requested review from AA-Turner, FFY00, Yhg1s, brettcannon, emmatyping, ericsnowcurrently, erlend-aasland, kumaraditya303, ncoghlan, pablogsal and warsaw as code owners August 4, 2026 22:49
@bedevere-app bedevere-app Bot added the awaiting core review label Aug 4, 2026
@DinoV DinoV added 3.15 bugs and security fixes topic-lazy-imports labels Aug 4, 2026
Yhg1s
Yhg1s reviewed Aug 5, 2026
View reviewed changes
Comment thread Lib/test/test_lazy_import/__init__.py Outdated
assert_python_ok("-c", code)

def test_non_package_lazily_imported(self):
"""Accessing a nonexistent lazy submodule via parent attr raises AttributeError."""

@Yhg1s Yhg1s Aug 5, 2026

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.

Suggested change
"""Accessing a nonexistent lazy submodule via parent attr raises AttributeError."""
"""Accessing a nonexistent lazy submodule via parent attr raises ModuleNotFoundError."""

Sorry, something went wrong.

Uh oh!

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

DinoV reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Python/import.c
);
Py_DECREF(name);
}
obj = _PyEval_ImportNameWithImport(

@Yhg1s Yhg1s Aug 5, 2026

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.

Hm, does this change the error for lazy from ... import nonexistent_attr? We don't seem to have explicit tests for what that raises, just the chaining test?

Sorry, something went wrong.

Uh oh!

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

All reactions

@DinoV DinoV Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

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.

Nope, that'll be the same. In the from case we're already doing a full import (it's probably not super clear here because that's when lz_attr is not NULL and that's maybe not the best name)

Sorry, something went wrong.

Uh oh!

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

All reactions
@DinoV
Fix doc string and add new test
09e0325
@emmatyping

emmatyping commented Aug 5, 2026

Copy link
Copy Markdown
Member

Is there a reason there is a 3.15 specific PR here rather than backporting the one targeting main once that's merged? #155189

If so, it might be good to explain that in the PR description.

All reactions

Sorry, something went wrong.

Uh oh!

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

@DinoV

DinoV commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Is there a reason there is a 3.15 specific PR here rather than backporting the one targeting main once that's merged? #155189

If so, it might be good to explain that in the PR description.

Mainly because if we don't fix it in 3.15 I don't think we should ever fix it - it would probably be a breaking change as people would come to depend upon it so I think we should fix it here first or not fix it at all.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Yhg1s

Yhg1s commented Aug 6, 2026

Copy link
Copy Markdown
Member

Mainly because if we don't fix it in 3.15 I don't think we should ever fix it - it would probably be a breaking change as people would come to depend upon it so I think we should fix it here first or not fix it at all.

Let's get Hugo's opinion on getting this into the next RC then, and if he's okay with that, apply it to main first. (Doing things in the other direction makes future merges more awkward.) FWIW, I think this is such a clear corner case that I think it would be fine to change in 3.15.1 as well, but I'm not in charge :)

All reactions

Sorry, something went wrong.

Uh oh!

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

@Yhg1s

Yhg1s commented Aug 6, 2026

Copy link
Copy Markdown
Member

@hugovk ^

All reactions

Sorry, something went wrong.

Uh oh!

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

@hugovk

hugovk commented Aug 6, 2026

Copy link
Copy Markdown
Member

Yes, let's fix this for rc2, and do it in main first.

DinoV and terryjreedy reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

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

pablogsal
pablogsal reviewed Aug 10, 2026
View reviewed changes

@pablogsal pablogsal 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.

Some comments

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Lib/test/test_lazy_import/__init__.py Resolved

Uh oh!

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

Comment thread Lib/test/test_lazy_import/__init__.py Resolved

Uh oh!

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

Comment thread Lib/test/test_lazy_import/data/lazypkg/bar.py Resolved

Uh oh!

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

Comment thread Lib/test/test_lazy_import/__init__.py Resolved

Uh oh!

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

Comment thread Lib/test/test_lazy_import/data/lazypkg/bar.py Resolved

Uh oh!

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

Comment thread Lib/test/test_lazy_import/__init__.py
assert_python_ok("-c", code)

def test_non_package_lazily_imported(self):
"""Accessing a nonexistent lazy submodule via parent attr raises ModuleNotFoundError."""

@pablogsal pablogsal Aug 10, 2026

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.

Nit: math.pi is an existing non-module attribute, and sys.doesnotexist is a missing attribute rather than a submodule. Can we describe those cases directly?

Sorry, something went wrong.

Uh oh!

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

All reactions

@DinoV DinoV Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

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.

@pablogsal I've fixed up these in the main PR (#155189), I'm going to close this one per the discussion above.

Sorry, something went wrong.

Uh oh!

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

All reactions
@DinoV DinoV closed this Aug 10, 2026
@DinoV DinoV mentioned this pull request Aug 14, 2026
gh-155194: Fix not raising on non-module import #155189
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Yhg1s Yhg1s Yhg1s left review comments
@pablogsal pablogsal pablogsal left review comments
@hugovk hugovk Awaiting requested review from hugovk
@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
@FFY00 FFY00 Awaiting requested review from FFY00 FFY00 is a code owner
@kumaraditya303 kumaraditya303 Awaiting requested review from kumaraditya303 kumaraditya303 is a code owner
@erlend-aasland erlend-aasland Awaiting requested review from erlend-aasland erlend-aasland is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner
@emmatyping emmatyping Awaiting requested review from emmatyping emmatyping is a code owner

Uh oh!

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

Assignees

No one assigned

Labels

3.15 bugs and security fixes awaiting core review skip news topic-lazy-imports

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.

5 participants

@DinoV @emmatyping @Yhg1s @hugovk @pablogsal
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.