Repository navigation
Closed
8 / 88 of 8 issues completedLabels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-lazy-importstype-featureA feature request or enhancementA feature request or enhancement
Description
Linked PRs
- gh-142349: Implement PEP 810 - Explicit lazy imports #142351
- gh-142349: Fix build errors from PEP 810 #144726
- gh-142349: Fix refcount corruption in lazy import specialization #144733
- gh-142349: Add CODEOWNERS for lazy imports #144840
- gh-142349: Fix ast.unparse for lazy import statements #144893
- gh-142349: Move all lazy-imports-by-hand to use the new lazy keyword #144894
- gh-142349: Add
help("lazy")support #149886 - [3.15] gh-142349: Add
help("lazy")support (GH-149886) #149889 - gh-142349: Improve
sys.lazy_modulesdocs #152622 - gh-142349: Clarify lazy import filters have positional-only parameters #144856
- [3.15] gh-142349: Clarify lazy import filters have positional-only parameters (GH-144856) #154808
- gh-142349: Clarify that sys.lazy_modules may contain extra items #155547
- [3.15] gh-142349: Clarify that sys.lazy_modules may contain extra items (GH-155547) #156934
- gh-142349: Document
LazyImportType.resolve()method #156936 - [3.15] gh-142349: Document
LazyImportType.resolve()method (GH-156936) #157296 - gh-142349: Simplify lazy import resolution #158282
- [3.15] gh-142349: Simplify lazy import resolution (GH-158282) #158569
- gh-142349: Update lazy import comments in whatsnew #158651
- [3.15] gh-142349: Update lazy import comments in whatsnew (GH-158651) #158652
- gh-142349: Update lazy imports C API and sys.flags documentation #158966
- [3.15] gh-142349: Update lazy imports C API and sys.flags documentation (GH-158966) #160110
Reacted by Savannah Ostrowski, Bartosz Sławecki, Peter Bierma, Soheab, Filipe Laíns, Cloud, baseplate-admin, Mickaël Schoentgen, Maurycy Pawłowski-Wieroński, Piotr Karmelita and 2 more
Reacted by Stan Ulbrych, Savannah Ostrowski, Bartosz Sławecki, Nice Zombies, devdanzin, Cody Maloney, Soheab, Filipe Laíns, An Long, Cloud and 2 more
Metadata
Metadata
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-lazy-importstype-featureA feature request or enhancementA feature request or enhancement
Activity
pythongh-142349: Remove spurious Py_DECREF on borrowed ref in LOAD_GL…
gh-142349: Fix refcount corruption in lazy import specialization (#14…
pythongh-142349: Implement PEP 810 - Explicit lazy imports (python#14…
pythongh-142349: Fix build errors from PEP 810 (python#144726)
pythongh-142349: Fix refcount corruption in lazy import specialization (
pythongh-142349: Add CODEOWNERS for lazy imports
gh-142349: Add CODEOWNERS for lazy imports (#144840)
pythongh-142349: Fix ast.unparse for lazy import statements
pythongh-142349: Move all lazy-imports-by-hand to use the new lazy ke…
gh-142349: Fix ast.unparse for lazy import statements (#144893)
DavidCEllis commentedon Feb 17, 2026
Should
__lazy_import__ignoresys.set_lazy_imports("none")?Currently it does:
A way to ignore this setting may actually be useful to handle circular imports, but I'm not sure if
__lazy_import__doing so is intentional.Setting the filter currently crashes with
__lazy_import__so I couldn't check that interaction - #144851.[-]Implement PEP 810[/-][+]Implement PEP 810 – Explicit lazy imports[/+]pythongh-142349: Implement PEP 810 - Explicit lazy imports (python#14…
pythongh-142349: Fix build errors from PEP 810 (python#144726)
pythongh-142349: Fix refcount corruption in lazy import specialization (
pythongh-142349: Add CODEOWNERS for lazy imports (python#144840)
pythongh-142349: Fix ast.unparse for lazy import statements (python#1…
hugovk commentedon Mar 10, 2026
This is merged and in alpha 7.
Anything more to do here, or shall we close this issue and mark the PEP as Final?
Oh, one thing:
__lazy_modules__isn't documented yet. @johnslavik I think you might have had a PR for this to the lazycabal fork?johnslavik commentedon Mar 10, 2026
I'd add that
sys.lazy_modulesis also undocumented and needs general polishing (ref GH-145057 and GH-145059), and from some discussions I've had it is not clear if we'd like to keep it public or make it private.I can't find it, but I'm happy to contribute more documentation as part of my interest in touching up lazy imports.
hugovk commentedon Mar 10, 2026
I was thinking of LazyImportsCabal#42.
pythongh-122575: pythongh-142349: fix sys.flags tuple size (it uninte…
gh-122575: gh-142349: fix sys.flags tuple size (it unintentionally in…
types.LazyImportTypeis not initialized #145452test_lazy_imports#145334sys.lazy_modules#145059sys.lazy_modulesis no longer a flat set #145057__lazy_import__crashes with user-defined filters #144851sys.lazy_modules#148587__lazy_modules__#148588pythongh-142349: Implement PEP 810 - Explicit lazy imports (python#14…
pythongh-142349: Fix build errors from PEP 810 (python#144726)
pythongh-142349: Fix refcount corruption in lazy import specialization (
pythongh-142349: Add CODEOWNERS for lazy imports (python#144840)
pythongh-142349: Fix ast.unparse for lazy import statements (python#1…
pythongh-122575: pythongh-142349: fix sys.flags tuple size (it uninte…
pythongh-142349: Add `help("lazy")` support
gh-142349: Add `help("lazy")` support (#149886)
[3.15] gh-142349: Add `help("lazy")` support (GH-149886) (#149889)
encukou commentedon Jun 29, 2026
sys.lazy_modulesdoesn't necessarily contain fully-qualified module names:This doesn't match the docs or PEP. Is this intended?
Also, unlike regular
import, lazy imports for non-modules work withoutfrom. This isn't clear from the PEP; is it intentional?gpshead commentedon Jun 29, 2026
Being lazy there's no way to know what the names and their types are until the actual import happens so i feel like this is expected. The error appears on first use.
I expect most codebases adopting lazy have also adopted static analysis to catch this at build/push/CI time.
encukou commentedon Jun 29, 2026
OK, so (for the first point) we should update the
lazy_modulesdocs (and PEP, to match the implementation).The (second) point is that it does not appear at all.
johnslavik commentedon Jun 29, 2026
I made these docs, how would you rephrase it?
I'm also unhappy with the current wording. Maybe "A set of strings capturing lazily imported modules or module members in the current interpreter. When a lazily imported module or module member is accessed for the first time and successfully resolved [reified?], its name is removed from this set.". WDYT?
johnslavik commentedon Jun 29, 2026
I made GH-152622, let's iterate there.
encukou commentedon Jun 30, 2026
The docs currently match the PEP, which should be changed to “accurately describes the implementation at the point where it is marked Final”. It's not about the docs.
Do you know why this wasn't implemented as specified?
Fully qualified module names would be useful as they could be passed to
importlib.import_moduleto load eagerly. The current implementation looks like it's the legacy form forpkgutil.resolve_name-- is that right?That doesn't look right:
DavidCEllis commentedon Jun 30, 2026
I think this is different depending on if the module has actually already been imported. If you're using the REPL then
typingis already insys.modules. If the module has already been imported then it still gets added but doesn't get removed.Using
threadinginstead, which isn't imported by the REPL.gh-142349: Clarify lazy import filters have positional-only parameters (
[3.15] gh-142349: Clarify lazy import filters have positional-only pa…
encukou commentedon Jul 29, 2026
So, what is
sys.lazy_modulesmeant to contain?brittanyrey commentedon Aug 3, 2026
Thread continued on discuss.py
pythongh-142349: Clarify lazy import filters have positional-only par…
gh-142349: Clarify that sys.lazy_modules may contain extra items (GH-…
[3.15] gh-142349: Clarify that sys.lazy_modules may contain extra ite…
types.LazyImportType.resolve()#157139gh-142349: Document `LazyImportType.resolve()` method (GH-156936)
[3.15] gh-142349: Document `LazyImportType.resolve()` method (GH-156936…
pythongh-142349: Clarify that sys.lazy_modules may contain extra items (
pythongh-142349: Document `LazyImportType.resolve()` method (pythonGH…
pythongh-142349: Document `LazyImportType.resolve()` method (pythonGH…
gh-142349: Simplify lazy import resolution (#158282)
[3.15] gh-142349: Simplify lazy import resolution (GH-158282) (#158569)
gh-142349: Update lazy import comments in whatsnew (#158651)
[3.15] gh-142349: Update lazy import comments in whatsnew (GH-158651) (…
[3.15] pythongh-142349: Simplify lazy import resolution (pythonGH-158282
[3.15] pythongh-142349: Clarify that sys.lazy_modules may contain ext…
[3.15] pythongh-142349: Document `LazyImportType.resolve()` method (p…
gh-142349: Update lazy imports C API and sys.flags documentation (#15…
[3.15] gh-142349: Update lazy imports C API and sys.flags documentati…
hugovk commentedon Oct 25, 2026
Python 3.15 has been released with lazy imports! Thanks everyone!