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

gh-155194: Fix not raising on non-module import by DinoV · Pull Request #155189 · python/cpython · GitHub

Repository navigation

gh-155194: Fix not raising on non-module import - #155189

Merged
DinoV merged 5 commits into
python:mainfrom
DinoV:lazy_fixes_main
Aug 14, 2026
Merged

DinoV merged 5 commits into
python:mainfrom
DinoV:lazy_fixes_main

Conversation

DinoV commented Aug 4, 2026 •
edited by bedevere-app Bot
Loading

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.

DinoV changed the title Fix not raising on non-module import gh-155194: Fix not raising on non-module import Aug 4, 2026
DinoV added the skip news label Aug 4, 2026
DinoV force-pushed the lazy_fixes_main branch from c802817 to 599c8d5 Compare August 4, 2026 21:40
DinoV marked this pull request as ready for review August 4, 2026 22:49
Comment thread Python/import.c

pablogsal 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

Only one small comment

""")
assert_python_ok("-c", code)

def test_missing_attribute_raises_import_error(self):

pablogsal Aug 11, 2026 •
edited
Loading

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

Maybe I am misreading this but i think this covers a different path. lazy import math.pi as pi still resolves pi to the float instead of raising.

Copy link
Copy Markdown
Contributor Author

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

This was in response to @Yhg1s who asked about this case and commented that we don't seem to have tests for it in #155188. I can add a test case for the lazy import math.pi as pi case too.

DinoV merged commit dffac61 into python:main Aug 14, 2026
55 checks passed
DinoV added 3.15 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Aug 14, 2026

Copy link
Copy Markdown

Thanks @DinoV for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

Copy link
Copy Markdown

Sorry, @DinoV, I could not cleanly backport this to 3.15 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker dffac6163e693cf80ed42cdc8e2cb5c0cb9577d7 3.15

bedevere-app Bot commented Aug 18, 2026

Copy link
Copy Markdown

GH-155983 is a backport of this pull request to the 3.15 branch.

bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Aug 18, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL