Skip to content

Commit d5ba5ec

Browse files
authored
PEP 810: Mark as accepted and address SC's feedback (#4684)
Signed-off-by: Pablo Galindo <[email protected]>
1 parent f221437 commit d5ba5ec

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

peps/pep-0810.rst

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ Author: Pablo Galindo <[email protected]>,
88
Noah Kim <[email protected]>,
99
Tim Stumbaugh <[email protected]>
1010
Discussions-To: https://discuss.python.org/t/104131
11-
Status: Draft
11+
Status: Accepted
1212
Type: Standards Track
1313
Created: 02-Oct-2025
1414
Python-Version: 3.15
1515
Post-History:
1616
`03-Oct-2025 <https://discuss.python.org/t/104131>`__,
17+
Resolution: `03-Nov-2025 <https://discuss.python.org/t/pep-810-explicit-lazy-imports/104131/466>`__
1718

1819

1920
Abstract
@@ -361,6 +362,15 @@ being imported, and (if applicable) the fromlist. An import remains lazy only
361362
if the filter function returns ``True``. If no lazy import filter is set, all
362363
*potentially lazy* imports are lazy.
363364

365+
Note on .pth files
366+
~~~~~~~~~~~~~~~~~~
367+
368+
The lazy import mechanism does not apply to .pth files processed by the
369+
``site`` module. While .pth files have special handling for lines that begin
370+
with ``import`` followed by a space or tab, this special handling will not be
371+
adapted to support lazy imports. Imports specified in .pth files remain eager
372+
as they always have been.
373+
364374
Lazy objects
365375
------------
366376

@@ -617,6 +627,9 @@ lazy imports filter:
617627
``"normal"`` (respect ``lazy`` keyword only), ``"all"`` (force all imports to be
618628
potentially lazy), or ``"none"`` (force all imports to be eager).
619629

630+
* ``sys.get_lazy_imports()`` - Returns the current lazy imports mode as a
631+
string: ``"normal"``, ``"all"``, or ``"none"``.
632+
620633
The filter function is called for every potentially lazy import, and must
621634
return ``True`` if the import should be lazy. This allows for fine-grained
622635
control over which imports should be lazy, useful for excluding modules with
@@ -692,6 +705,11 @@ The global lazy imports flag can be controlled through:
692705
* The ``PYTHON_LAZY_IMPORTS=<mode>`` environment variable
693706
* The ``sys.set_lazy_imports(mode)`` function (primarily for testing)
694707

708+
The precedence order for setting the lazy imports mode follows the standard
709+
Python pattern: ``sys.set_lazy_imports()`` takes highest precedence, followed
710+
by ``-X lazy_imports=<mode>``, then ``PYTHON_LAZY_IMPORTS=<mode>``. If none
711+
are specified, the mode defaults to ``"normal"``.
712+
695713
Where ``<mode>`` can be:
696714

697715
* ``"normal"`` (or unset): Only explicitly marked lazy imports are lazy

0 commit comments

Comments
 (0)