gh-151672: Treat string fromlist like __import__ for lazy imports#152322
Closed
vedikatai wants to merge 2 commits into
Closed
gh-151672: Treat string fromlist like __import__ for lazy imports#152322vedikatai 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.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
The following commit authors need to sign the Contributor License Agreement: |
Author
|
Closing: opened against upstream by mistake. Constraint was all public actions on vedikatai only — reopening as draft PRs on vedikatai/cpython. |
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, while__import__(name, fromlist="attr")returns the module.User impact
PEP 810 lazy-import users / libraries calling
__lazy_import__with a stringfromlist(valid for__import__) get surprising member objects instead of modules on 3.15/3.16.Bisect
Tied to lazy-imports implementation (
Python/import.c_PyImport_LazyImportModuleLevelObject), labeled 3.15/3.16. Not bisected to a single commit in this audit (feature-area, not a 3.16.0a0-only slip).Related open PR: #151827 — coordinate before landing both.
Diff
Normalize Unicode
fromlistto a 1-tuple before_PyLazyImport_Newand parent registration (~15 lines C).Test results (3.16.0a0)
Targeted import/lazy-import paths exercised via reproducer; full lazy-import suite not re-run end-to-end in audit window.
Audit provenance
/tmp/cpython-regression-audit.md.