gh-151672: Treat string fromlist like __import__ for lazy imports#1
Closed
vedikatai wants to merge 2 commits into
Closed
gh-151672: Treat string fromlist like __import__ for lazy imports#1vedikatai wants to merge 2 commits into
vedikatai wants to merge 2 commits into
Conversation
… 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.
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
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.
Summary
Fixes python/cpython#151672:
__lazy_import__(name, fromlist="attr")resolved to the attribute, not the module.Target:
vedikatai/cpythononly (not upstreampython/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 Unicodefromlistto a 1-tuple.Tests (3.16.0a0)
__lazy_import__("json", fromlist="load").resolve()ismodule.Note
Earlier mistaken draft on python#152322 was closed; this is the correct venue.