Skip to content

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

Open
DinoV wants to merge 3 commits into
python:mainfrom
DinoV:lazy_fixes_main
Open

gh-155194: Fix not raising on non-module import#155189
DinoV wants to merge 3 commits into
python:mainfrom
DinoV:lazy_fixes_main

Conversation

@DinoV

@DinoV DinoV commented Aug 4, 2026

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 DinoV changed the title Fix not raising on non-module import gh-155194: Fix not raising on non-module import Aug 4, 2026
@DinoV DinoV added the skip news label Aug 4, 2026
Comment thread Python/import.c
Comment on lines 4597 to 4605
if (fromlist && PyTuple_Check(fromlist) && PyTuple_GET_SIZE(fromlist)) {
for (Py_ssize_t i = 0; i < PyTuple_GET_SIZE(fromlist); i++) {
if (register_from_lazy_on_parent(tstate, abs_name,
PyTuple_GET_ITEM(fromlist, i)) < 0)
{
goto error;
}
}
}

@encukou encukou Aug 10, 2026

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.

Would it make sense to also remove this, so that math instead of math.pi shows up in sys.lazy_modules?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants