@@ -8,12 +8,13 @@ Author: Pablo Galindo <pablogsal@python.org>,
88 Noah Kim <noahbkim@gmail.com>,
99 Tim Stumbaugh <me@tjstum.com>
1010Discussions-To: https://discuss.python.org/t/104131
11- Status: Draft
11+ Status: Accepted
1212Type: Standards Track
1313Created: 02-Oct-2025
1414Python-Version: 3.15
1515Post-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
1920Abstract
@@ -361,6 +362,15 @@ being imported, and (if applicable) the fromlist. An import remains lazy only
361362if the filter function returns ``True ``. If no lazy import filter is set, all
362363*potentially lazy
8000
* 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+
364374Lazy 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+
620633The filter function is called for every potentially lazy import, and must
621634return ``True `` if the import should be lazy. This allows for fine-grained
622635control 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+
695713Where ``<mode> `` can be:
696714
697715* ``"normal" `` (or unset): Only explicitly marked lazy imports are lazy
0 commit comments