Skip to content

gh-151672: Treat string fromlist like __import__ for lazy imports#1

Closed
vedikatai wants to merge 2 commits into
mainfrom
audit/fix-151672-lazy-fromlist
Closed

gh-151672: Treat string fromlist like __import__ for lazy imports#1
vedikatai wants to merge 2 commits into
mainfrom
audit/fix-151672-lazy-fromlist

Conversation

@vedikatai

Copy link
Copy Markdown
Owner

Summary

Fixes python/cpython#151672: __lazy_import__(name, fromlist="attr") resolved to the attribute, not the module.

Target: vedikatai/cpython only (not upstream python/cpython).

User impact

PEP 810 / lazy-import callers expecting __import__ semantics.

Bisect

Lazy-imports feature area (3.15/3.16 labels); not bisected to a single 3.16.0a0 commit.

Diff

Python/import.c — normalize Unicode fromlist to a 1-tuple.

Tests (3.16.0a0)

__lazy_import__("json", fromlist="load").resolve() is module.

Note

Earlier mistaken draft on python#152322 was closed; this is the correct venue.

… path

set_new() used make_new_set(), which GC-tracked the empty set before
set_init() populated it from the iterable. That left the same half-built
window the vectorcall path already closed, so concurrent GC / get_objects()
could observe an inconsistent set and crash on edge cases.

Allocate untracked in set_new() and call _PyObject_GC_TRACK() only after
set_init() succeeds (skipping if already tracked for re-init).
__lazy_import__(name, fromlist="attr") resolved to the attribute
instead of the module. Normalize a string fromlist to a 1-tuple so
resolve() returns the module, matching __import__ behavior.
@vedikatai vedikatai closed this Jun 26, 2026
@vedikatai vedikatai deleted the audit/fix-151672-lazy-fromlist branch June 27, 2026 10:24
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.

__lazy_import__ with a string fromlist doesn't resolve to the module being imported

2 participants