From ae321421b501ce0b08e91a537dd6c8fd654b6e60 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Mon, 3 Nov 2025 14:11:02 -0500 Subject: [PATCH] PEP 810: Mark as accepted and address SC's feedback Signed-off-by: Pablo Galindo --- peps/pep-0810.rst | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/peps/pep-0810.rst b/peps/pep-0810.rst index c2b7e2a2e39..ed12385a0dd 100644 --- a/peps/pep-0810.rst +++ b/peps/pep-0810.rst @@ -8,12 +8,13 @@ Author: Pablo Galindo , Noah Kim , Tim Stumbaugh Discussions-To: https://discuss.python.org/t/104131 -Status: Draft +Status: Accepted Type: Standards Track Created: 02-Oct-2025 Python-Version: 3.15 Post-History: `03-Oct-2025 `__, +Resolution: `03-Nov-2025 `__ Abstract @@ -361,6 +362,15 @@ being imported, and (if applicable) the fromlist. An import remains lazy only if the filter function returns ``True``. If no lazy import filter is set, all *potentially lazy* imports are lazy. +Note on .pth files +~~~~~~~~~~~~~~~~~~ + +The lazy import mechanism does not apply to .pth files processed by the +``site`` module. While .pth files have special handling for lines that begin +with ``import`` followed by a space or tab, this special handling will not be +adapted to support lazy imports. Imports specified in .pth files remain eager +as they always have been. + Lazy objects ------------ @@ -617,6 +627,9 @@ lazy imports filter: ``"normal"`` (respect ``lazy`` keyword only), ``"all"`` (force all imports to be potentially lazy), or ``"none"`` (force all imports to be eager). +* ``sys.get_lazy_imports()`` - Returns the current lazy imports mode as a + string: ``"normal"``, ``"all"``, or ``"none"``. + The filter function is called for every potentially lazy import, and must return ``True`` if the import should be lazy. This allows for fine-grained 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: * The ``PYTHON_LAZY_IMPORTS=`` environment variable * The ``sys.set_lazy_imports(mode)`` function (primarily for testing) +The precedence order for setting the lazy imports mode follows the standard +Python pattern: ``sys.set_lazy_imports()`` takes highest precedence, followed +by ``-X lazy_imports=``, then ``PYTHON_LAZY_IMPORTS=``. If none +are specified, the mode defaults to ``"normal"``. + Where ```` can be: * ``"normal"`` (or unset): Only explicitly marked lazy imports are lazy