]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.15] gh-149321: Remove lazy_imports=none startup mode (GH-149389) (#150129)
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Mon, 8 Jun 2026 22:55:57 +0000 (23:55 +0100)
committerGitHub <noreply@github.com>
Mon, 8 Jun 2026 22:55:57 +0000 (22:55 +0000)
18 files changed:
Doc/c-api/import.rst
Doc/data/python3.15.abi
Doc/library/sys.rst
Doc/reference/simple_stmts.rst
Doc/tools/removed-ids.txt
Doc/using/cmdline.rst
Doc/whatsnew/3.15.rst
Include/import.h
Lib/test/test_lazy_import/__init__.py
Lib/test/test_lazy_import/data/global_off.py [deleted file]
Misc/NEWS.d/3.15.0a8.rst
Misc/NEWS.d/next/Core_and_Builtins/2026-05-05-12-00-00.gh-issue-149321.remove-lazy-imports-none.rst [new file with mode: 0644]
Modules/_testcapi/import.c
Python/ceval.c
Python/clinic/sysmodule.c.h
Python/initconfig.c
Python/pylifecycle.c
Python/sysmodule.c

index e2d363b911a87c65003a3f6c00a81e141873ae7d..ec9462931d56c2c671a1584ba00dbe2bd747db0a 100644 (file)
@@ -393,11 +393,6 @@ Importing Modules
 
       Make all imports lazy by default.
 
-   .. c:enumerator:: PyImport_LAZY_NONE
-
-      Disable lazy imports entirely. Even explicit ``lazy`` statements become
-      eager imports.
-
    .. versionadded:: 3.15
 
 .. c:function:: PyObject* PyImport_CreateModuleFromInitfunc(PyObject *spec, PyObject* (*initfunc)(void))
index aea9ff48a62763322e6ef156e8767a1735382bfd..d769d6a764c62ebdb2bd136cd7bc06841990363c 100644 (file)
       <underlying-type type-id='type-id-45'/>
       <enumerator name='PyImport_LAZY_NORMAL' value='0'/>
       <enumerator name='PyImport_LAZY_ALL' value='1'/>
-      <enumerator name='PyImport_LAZY_NONE' value='2'/>
     </enum-decl>
     <typedef-decl name='PyImport_LazyImportsMode' type-id='type-id-1652' filepath='./Include/import.h' line='95' column='1' id='type-id-1651'/>
     <typedef-decl name='conversion_func' type-id='type-id-1456' filepath='./Include/internal/pycore_ceval.h' line='282' column='1' id='type-id-1653'/>
index 4683fc03f843a2770765ddcfda5844a99f12d410..b4f410a020f86e129966e6d48325b3aae3c3e000 100644 (file)
@@ -919,8 +919,6 @@ always available. Unless explicitly noted otherwise, all variables are read-only
    * ``"normal"``: Only imports explicitly marked with the ``lazy`` keyword
      are lazy
    * ``"all"``: All top-level imports are potentially lazy
-   * ``"none"``: All lazy imports are suppressed (even explicitly marked
-     ones)
 
    See also :func:`set_lazy_imports` and :pep:`810`.
 
@@ -1772,8 +1770,6 @@ always available. Unless explicitly noted otherwise, all variables are read-only
    * ``"normal"``: Only imports explicitly marked with the ``lazy`` keyword
      are lazy
    * ``"all"``: All top-level imports become potentially lazy
-   * ``"none"``: All lazy imports are suppressed (even explicitly marked
-     ones)
 
    This function is intended for advanced users who need to control lazy
    imports across their entire application. Library developers should
index f8e54aa0a108c8db20463ef5f7fc77cce2fbb116..0f134604b5d922b69e724960b8a9c39c51f9db75 100644 (file)
@@ -965,10 +965,6 @@ Imports inside functions, class bodies, or
 :keyword:`try`/:keyword:`except`/:keyword:`finally` blocks are always eager,
 regardless of :attr:`!__lazy_modules__`.
 
-Setting ``-X lazy_imports=none`` (or the :envvar:`PYTHON_LAZY_IMPORTS`
-environment variable to ``none``) overrides :attr:`!__lazy_modules__` and
-forces all imports to be eager.
-
 .. versionadded:: 3.15
 
 .. _future:
index 2d5917f4d240f5e0c02d59d21a1caabcbd0017ee..474376f4bd7baed21022f8141c6233a1dd39d8c2 100644 (file)
@@ -6,6 +6,9 @@ c-api/file.html: deprecated-api
 
 library/asyncio-task.html: terminating-a-task-group
 
+# Removed APIs
+c-api/import.html: c.PyImport_LazyImportsMode.PyImport_LAZY_NONE
+
 ## Old names for grammar tokens
 reference/expressions.html: grammar-token-python-grammar-comp_for
 reference/expressions.html: grammar-token-python-grammar-comp_if
index d84cd42062a678180885ca74502fb821c6d40215..19997eb5fed9631083212f23f5f9452811404e1d 100644 (file)
@@ -705,10 +705,9 @@ Miscellaneous options
 
      .. versionadded:: 3.14
 
-   * :samp:`-X lazy_imports={all,none,normal}` controls lazy import behavior.
-     ``all`` makes all imports lazy by default, ``none`` disables lazy imports
-     entirely (even explicit ``lazy`` statements become eager), and ``normal``
-     (the default) respects the ``lazy`` keyword in source code.
+   * :samp:`-X lazy_imports={all,normal}` controls lazy import behavior.
+     ``all`` makes all imports lazy by default, and ``normal`` (the default)
+     respects the ``lazy`` keyword in source code.
      See also :envvar:`PYTHON_LAZY_IMPORTS`.
 
      .. versionadded:: 3.15
@@ -1416,10 +1415,9 @@ conflict.
 
 .. envvar:: PYTHON_LAZY_IMPORTS
 
-   Controls lazy import behavior. Accepts three values: ``all`` makes all
-   imports lazy by default, ``none`` disables lazy imports entirely (even
-   explicit ``lazy`` statements become eager), and ``normal`` (the default)
-   respects the ``lazy`` keyword in source code.
+   Controls lazy import behavior. Accepts two values: ``all`` makes all
+   imports lazy by default, and ``normal`` (the default) respects the
+   ``lazy`` keyword in source code.
 
    See also the :option:`-X lazy_imports <-X>` command-line option.
 
index 7d20805c4c5775430063710a1d49b735c3e0a360..36a18f15a3deb2ee6b7d5620345f981d6699626f 100644 (file)
@@ -157,11 +157,10 @@ making it straightforward to diagnose and debug the failure.
 For cases where you want to enable lazy loading globally without modifying
 source code, Python provides the :option:`-X lazy_imports <-X>` command-line
 option and the :envvar:`PYTHON_LAZY_IMPORTS` environment variable. Both
-accept three values: ``all`` makes all imports lazy by default, ``none``
-disables lazy imports entirely (even explicit ``lazy`` statements become
-eager), and ``normal`` (the default) respects the ``lazy`` keyword in source
-code. The :func:`sys.set_lazy_imports` and :func:`sys.get_lazy_imports`
-functions allow changing and querying this mode at runtime.
+accept two values: ``all`` makes all imports lazy by default, and ``normal``
+(the default) respects the ``lazy`` keyword in source code. The
+:func:`sys.set_lazy_imports` and :func:`sys.get_lazy_imports` functions allow
+changing and querying this mode at runtime.
 
 For more selective control, :func:`sys.set_lazy_imports_filter` accepts a
 callable that determines whether a specific module should be loaded lazily.
index 6f1c13787b8569a4c20b10adfdcf081838222d63..c062e46bff46bf726316a1c498be8eda89b023c8 100644 (file)
@@ -90,8 +90,7 @@ PyAPI_FUNC(int) PyImport_AppendInittab(
 
 typedef enum {
     PyImport_LAZY_NORMAL,
-    PyImport_LAZY_ALL,
-    PyImport_LAZY_NONE
+    PyImport_LAZY_ALL
 } PyImport_LazyImportsMode;
 
 #ifndef Py_LIMITED_API
index aeb275b958ec5e6c12f4fd3f5592d5e28676f242..c99c22491028d33d42f3a2d8fd7e0b78a2708cdc 100644 (file)
@@ -171,10 +171,18 @@ class LazyImportTests(LazyImportTestCase):
 class GlobalLazyImportModeTests(LazyImportTestCase):
     """Tests for sys.set_lazy_imports() global mode control."""
 
-    def test_global_off(self):
-        """Mode 'none' should disable lazy imports entirely."""
-        import test.test_lazy_import.data.global_off
-        self.assertIn("test.test_lazy_import.data.basic2", sys.modules)
+    def tearDown(self):
+        for key in list(sys.modules.keys()):
+            if key.startswith('test.test_lazy_import.data'):
+                del sys.modules[key]
+
+        sys.set_lazy_imports_filter(None)
+        sys.set_lazy_imports("normal")
+
+    def test_global_off_rejected(self):
+        """Mode 'none' is not supported."""
+        with self.assertRaises(ValueError):
+            sys.set_lazy_imports("none")
 
     def test_global_on(self):
         """Mode 'all' should make regular imports lazy."""
@@ -612,9 +620,6 @@ class SysLazyImportsAPITests(LazyImportTestCase):
         sys.set_lazy_imports("all")
         self.assertEqual(sys.get_lazy_imports(), "all")
 
-        sys.set_lazy_imports("none")
-        self.assertEqual(sys.get_lazy_imports(), "none")
-
     def test_get_lazy_imports_filter_default(self):
         """get_lazy_imports_filter should return None by default."""
         sys.set_lazy_imports_filter(None)
@@ -1111,68 +1116,16 @@ class CommandLineAndEnvVarTests(unittest.TestCase):
         self.assertEqual(result.returncode, 0, f"stderr: {result.stderr}")
         self.assertIn("LAZY", result.stdout)
 
-    def test_cli_lazy_imports_none_forces_all_imports_eager(self):
-        """-X lazy_imports=none should force all imports to be eager."""
-        code = textwrap.dedent("""
-            import sys
-            # Even explicit lazy imports should be eager in 'none' mode
-            lazy import json
-            if 'json' in sys.modules:
-                print("EAGER")
-            else:
-                print("LAZY")
-        """)
+    def test_cli_lazy_imports_none_is_rejected(self):
+        """-X lazy_imports=none should be rejected."""
         result = subprocess.run(
-            [sys.executable, "-X", "lazy_imports=none", "-c", code],
+            [sys.executable, "-X", "lazy_imports=none", "-c", "pass"],
             capture_output=True,
             text=True
         )
-        self.assertEqual(result.returncode, 0, f"stderr: {result.stderr}")
-        self.assertIn("EAGER", result.stdout)
-
-    @support.requires_resource("cpu")
-    def test_cli_lazy_imports_modes_import_stdlib_modules(self):
-        """-X lazy_imports modes should import available stdlib modules."""
-        # Do not smoke-test modules with intentional import-time effects.
-        import_side_effect_modules = {"antigravity", "this"}
-        importable = []
-
-        for module in sorted(sys.stdlib_module_names):
-            if module in import_side_effect_modules:
-                continue
-
-            with self.subTest(module=module):
-                code = f"import {module}; print({module})"
-                baseline = subprocess.run(
-                    [sys.executable, "-I", "-c", code],
-                    capture_output=True,
-                    text=True,
-                    timeout=60,
-                )
-                if baseline.returncode:
-                    # sys.stdlib_module_names includes modules for other
-                    # platforms and optional extension modules not built here.
-                    continue
-                importable.append(module)
-
-                for mode in ("normal", "none"):
-                    with self.subTest(module=module, mode=mode):
-                        result = subprocess.run(
-                            [
-                                sys.executable,
-                                "-I",
-                                "-X",
-                                f"lazy_imports={mode}",
-                                "-c",
-                                code,
-                            ],
-                            capture_output=True,
-                            text=True,
-                            timeout=60,
-                        )
-                        self.assertEqual(result.returncode, 0, result.stderr)
-
-        self.assertGreater(len(importable), 100)
+        self.assertNotEqual(result.returncode, 0)
+        self.assertIn("-X lazy_imports: invalid value", result.stderr)
+        self.assertIn("expected 'all' or 'normal'", result.stderr)
 
     def test_cli_lazy_imports_normal_respects_lazy_keyword_only(self):
         """-X lazy_imports=normal should respect lazy keyword only."""
@@ -1221,77 +1174,27 @@ class CommandLineAndEnvVarTests(unittest.TestCase):
         self.assertEqual(result.returncode, 0, f"stderr: {result.stderr}")
         self.assertIn("LAZY", result.stdout)
 
-    def test_env_var_lazy_imports_none_disables_all_lazy(self):
-        """PYTHON_LAZY_IMPORTS=none should disable all lazy imports."""
-        code = textwrap.dedent("""
-            import sys
-            lazy import json
-            if 'json' in sys.modules:
-                print("EAGER")
-            else:
-                print("LAZY")
-        """)
+    def test_env_var_lazy_imports_none_is_rejected(self):
+        """PYTHON_LAZY_IMPORTS=none should be rejected."""
         import os
         env = os.environ.copy()
         env["PYTHON_LAZY_IMPORTS"] = "none"
         result = subprocess.run(
-            [sys.executable, "-c", code],
+            [sys.executable, "-c", "pass"],
             capture_output=True,
             text=True,
             env=env
         )
-        self.assertEqual(result.returncode, 0, f"stderr: {result.stderr}")
-        self.assertIn("EAGER", result.stdout)
-
-    def test_cli_lazy_imports_none_disables_dunder_lazy_modules(self):
-        """-X lazy_imports=none should override __lazy_modules__."""
-        code = textwrap.dedent("""
-            import sys
-            __lazy_modules__ = ["json"]
-            import json
-            if 'json' in sys.modules:
-                print("EAGER")
-            else:
-                print("LAZY")
-        """)
-        result = subprocess.run(
-            [sys.executable, "-X", "lazy_imports=none", "-c", code],
-            capture_output=True,
-            text=True,
-        )
-        self.assertEqual(result.returncode, 0, f"stderr: {result.stderr}")
-        self.assertIn("EAGER", result.stdout)
-
-    def test_env_var_lazy_imports_none_disables_dunder_lazy_modules(self):
-        """PYTHON_LAZY_IMPORTS=none should override __lazy_modules__."""
-        code = textwrap.dedent("""
-            import sys
-            __lazy_modules__ = ["json"]
-            import json
-            if 'json' in sys.modules:
-                print("EAGER")
-            else:
-                print("LAZY")
-        """)
-        import os
-
-        env = os.environ.copy()
-        env["PYTHON_LAZY_IMPORTS"] = "none"
-        result = subprocess.run(
-            [sys.executable, "-c", code],
-            capture_output=True,
-            text=True,
-            env=env,
-        )
-        self.assertEqual(result.returncode, 0, f"stderr: {result.stderr}")
-        self.assertIn("EAGER", result.stdout)
+        self.assertNotEqual(result.returncode, 0)
+        self.assertIn("PYTHON_LAZY_IMPORTS: invalid value", result.stderr)
+        self.assertIn("expected 'all' or 'normal'", result.stderr)
 
     def test_cli_overrides_env_var(self):
         """Command-line option should take precedence over environment variable."""
         # PEP 810: -X lazy_imports takes precedence over PYTHON_LAZY_IMPORTS
         code = textwrap.dedent("""
             import sys
-            lazy import json
+            import json
             if 'json' in sys.modules:
                 print("EAGER")
             else:
@@ -1299,23 +1202,23 @@ class CommandLineAndEnvVarTests(unittest.TestCase):
         """)
         import os
         env = os.environ.copy()
-        env["PYTHON_LAZY_IMPORTS"] = "all"  # env says all
+        env["PYTHON_LAZY_IMPORTS"] = "all"  # env says all imports are lazy
         result = subprocess.run(
-            [sys.executable, "-X", "lazy_imports=none", "-c", code],  # CLI says none
+            [sys.executable, "-X", "lazy_imports=normal", "-c", code],
             capture_output=True,
             text=True,
             env=env
         )
         self.assertEqual(result.returncode, 0, f"stderr: {result.stderr}")
-        # CLI should win - imports should be eager
+        # CLI should win, so a regular import should stay eager.
         self.assertIn("EAGER", result.stdout)
 
     def test_sys_set_lazy_imports_overrides_cli(self):
         """sys.set_lazy_imports() should take precedence over CLI option."""
         code = textwrap.dedent("""
             import sys
-            sys.set_lazy_imports("none")  # Override CLI
-            lazy import json
+            sys.set_lazy_imports("normal")  # Override CLI
+            import json
             if 'json' in sys.modules:
                 print("EAGER")
             else:
@@ -2037,9 +1940,10 @@ class LazyImportDisTests(unittest.TestCase):
 class LazyCApiTests(LazyImportTestCase):
     def test_set_matches_sys(self):
         self.assertEqual(_testcapi.PyImport_GetLazyImportsMode(), sys.get_lazy_imports())
-        for mode in ("normal", "all", "none"):
+        for mode in ("normal", "all"):
             _testcapi.PyImport_SetLazyImportsMode(mode)
             self.assertEqual(_testcapi.PyImport_GetLazyImportsMode(), sys.get_lazy_imports())
+        self.assertRaises(ValueError, _testcapi.PyImport_SetLazyImportsMode, "none")
 
     def test_filter_matches_sys(self):
         self.assertEqual(_testcapi.PyImport_GetLazyImportsFilter(), sys.get_lazy_imports_filter())
diff --git a/Lib/test/test_lazy_import/data/global_off.py b/Lib/test/test_lazy_import/data/global_off.py
deleted file mode 100644 (file)
index 95d1511..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-import sys
-
-sys.set_lazy_imports("none")
-
-lazy import test.test_lazy_import.data.basic2 as basic2
index 3c6da8b6ab48e31cfe766b8d981b178c5bb2e78a..28e9ca85166620f72ed2df4e7a4ccbd325920789 100644 (file)
@@ -180,16 +180,6 @@ dealing with contradictions in ``make_bottom``.
 
 ..
 
-.. date: 2026-03-24-13-06-52
-.. gh-issue: 146369
-.. nonce: 6wDI6S
-.. section: Core and Builtins
-
-Ensure ``-X lazy_imports=none`` and ``PYTHON_LAZY_IMPORTS=none`` override
-:attr:`~module.__lazy_modules__`. Patch by Hugo van Kemenade.
-
-..
-
 .. date: 2026-03-22-19-30-00
 .. gh-issue: 146308
 .. nonce: AxnRVA
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-05-05-12-00-00.gh-issue-149321.remove-lazy-imports-none.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-05-05-12-00-00.gh-issue-149321.remove-lazy-imports-none.rst
new file mode 100644 (file)
index 0000000..44e96ce
--- /dev/null
@@ -0,0 +1 @@
+Do not support ``none`` as a lazy imports mode.
index ebb1032fdd1c3206054084053fc297aa30fd8dd1..384a8f52da4b98423b0535207b34007ce14eafb4 100644 (file)
@@ -41,8 +41,6 @@ pyimport_setlazyimportsmode(PyObject *self, PyObject *args)
         PyImport_SetLazyImportsMode(PyImport_LAZY_NORMAL);
     } else if (strcmp(PyUnicode_AsUTF8(mode), "all") == 0) {
         PyImport_SetLazyImportsMode(PyImport_LAZY_ALL);
-    } else if (strcmp(PyUnicode_AsUTF8(mode), "none") == 0) {
-        PyImport_SetLazyImportsMode(PyImport_LAZY_NONE);
     } else {
         PyErr_SetString(PyExc_ValueError, "invalid mode");
         return NULL;
@@ -59,8 +57,6 @@ pyimport_getlazyimportsmode(PyObject *self, PyObject *args)
             return PyUnicode_FromString("normal");
         case PyImport_LAZY_ALL:
             return PyUnicode_FromString("all");
-        case PyImport_LAZY_NONE:
-            return PyUnicode_FromString("none");
         default:
             PyErr_SetString(PyExc_ValueError, "unknown mode");
             return NULL;
index a080ae42b937667f79c114058001bb91de5b8a0e..5661200e74d0a55bce71bb4b5c2a2e29f8e313b8 100644 (file)
@@ -3072,12 +3072,8 @@ _PyEval_LazyImportName(PyThreadState *tstate, PyObject *builtins,
                        PyObject *fromlist, PyObject *level, int lazy)
 {
     PyObject *res = NULL;
-    PyImport_LazyImportsMode mode = PyImport_GetLazyImportsMode();
     // Check if global policy overrides the local syntax
-    switch (mode) {
-        case PyImport_LAZY_NONE:
-            lazy = 0;
-            break;
+    switch (PyImport_GetLazyImportsMode()) {
         case PyImport_LAZY_ALL:
             if (!lazy) {
                 lazy = is_lazy_import_module_level();
@@ -3087,11 +3083,15 @@ _PyEval_LazyImportName(PyThreadState *tstate, PyObject *builtins,
             break;
     }
 
-    if (!lazy && mode != PyImport_LAZY_NONE && is_lazy_import_module_level()) {
+    if (!lazy) {
         // See if __lazy_modules__ forces this to be lazy.
-        lazy = check_lazy_import_compatibility(tstate, globals, name, level);
-        if (lazy < 0) {
-            return NULL;
+        // __lazy_modules__ only applies at module level; exec() inside
+        // functions or classes should remain eager.
+        if (is_lazy_import_module_level()) {
+            lazy = check_lazy_import_compatibility(tstate, globals, name, level);
+            if (lazy < 0) {
+                return NULL;
+            }
         }
     }
 
index 75ce493f8688d691bdfe46fd0c070e141404309b..067b0b0a1fb035ace563bbda3872c021115c45fd 100644 (file)
@@ -1915,7 +1915,6 @@ PyDoc_STRVAR(sys_set_lazy_imports__doc__,
 "\n"
 "The mode parameter must be one of the following strings:\n"
 "- \"all\": All top-level imports become potentially lazy\n"
-"- \"none\": All lazy imports are suppressed (even explicitly marked ones)\n"
 "- \"normal\": Only explicitly marked imports (with \'lazy\' keyword) are\n"
 "  lazy\n"
 "\n"
@@ -1981,7 +1980,6 @@ PyDoc_STRVAR(sys_get_lazy_imports__doc__,
 "Gets the global lazy imports mode.\n"
 "\n"
 "Returns \"all\" if all top level imports are potentially lazy.\n"
-"Returns \"none\" if all explicitly marked lazy imports are suppressed.\n"
 "Returns \"normal\" if only explicitly marked imports are lazy.");
 
 #define SYS_GET_LAZY_IMPORTS_METHODDEF    \
@@ -2123,4 +2121,4 @@ exit:
 #ifndef SYS_GETANDROIDAPILEVEL_METHODDEF
     #define SYS_GETANDROIDAPILEVEL_METHODDEF
 #endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */
-/*[clinic end generated code: output=94838be2d96b4522 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=3ccdb73f733fc82c input=a9049054013a1b77]*/
index a996fb117aab9d2eb764e6f0545729a25a67815d..bebadcc76111b77301b6b24e2355bd89b093830a 100644 (file)
@@ -455,7 +455,7 @@ static const char usage_xoptions[] =
 "         log imports of already-loaded modules; also #e{PYTHONPROFILEIMPORTTIME}\n"
 "#s{-X} #L{int_max_str_digits}#b{=N}: limit the size of int<->str conversions;\n"
 "         0 disables the limit; also #e{PYTHONINTMAXSTRDIGITS}\n"
-"#s{-X} #L{lazy_imports}#b{=[all|none|normal]}: control global lazy imports;\n"
+"#s{-X} #L{lazy_imports}#b{=[all|normal]}: control global lazy imports;\n"
 "         default is #B{normal}; also #e{PYTHON_LAZY_IMPORTS}\n"
 "#s{-X} #L{no_debug_ranges}: don't include extra location information in code objects;\n"
 "         also #e{PYTHONNODEBUGRANGES}\n"
@@ -1065,7 +1065,8 @@ config_check_consistency(const PyConfig *config)
     assert(config->int_max_str_digits >= 0);
     // cpu_count can be -1 if the user doesn't override it.
     assert(config->cpu_count != 0);
-    // lazy_imports can be -1 (default), 0 (off), or 1 (on).
+    // lazy_imports can be -1 (default) or 1 (on). 0 is rejected later
+    // for embedders with an error message.
     assert(config->lazy_imports >= -1 && config->lazy_imports <= 1);
     // config->use_frozen_modules is initialized later
     // by _PyConfig_InitImportConfig().
@@ -2437,15 +2438,12 @@ config_init_lazy_imports(PyConfig *config)
         if (strcmp(env, "all") == 0) {
             lazy_imports = 1;
         }
-        else if (strcmp(env, "none") == 0) {
-            lazy_imports = 0;
-        }
         else if (strcmp(env, "normal") == 0) {
             lazy_imports = -1;
         }
         else {
             return _PyStatus_ERR("PYTHON_LAZY_IMPORTS: invalid value; "
-                                 "expected 'all', 'none', or 'normal'");
+                                 "expected 'all' or 'normal'");
         }
         config->lazy_imports = lazy_imports;
     }
@@ -2455,15 +2453,12 @@ config_init_lazy_imports(PyConfig *config)
         if (wcscmp(x_value, L"all") == 0) {
             lazy_imports = 1;
         }
-        else if (wcscmp(x_value, L"none") == 0) {
-            lazy_imports = 0;
-        }
         else if (wcscmp(x_value, L"normal") == 0) {
             lazy_imports = -1;
         }
         else {
             return _PyStatus_ERR("-X lazy_imports: invalid value; "
-                                 "expected 'all', 'none', or 'normal'");
+                                 "expected 'all' or 'normal'");
         }
         config->lazy_imports = lazy_imports;
     }
index f8d9836d90ba789a7a3642ca55d84d39a4983db1..0bdc7ddd92dc823fbd941dfb94e42fce061b727d 100644 (file)
@@ -1486,15 +1486,11 @@ init_interp_main(PyThreadState *tstate)
 
     // Initialize lazy imports based on configuration. Do this after site
     // module is imported to avoid circular imports during startup.
-    if (config->lazy_imports != -1) {
-        PyImport_LazyImportsMode lazy_mode;
-        if (config->lazy_imports == 1) {
-            lazy_mode = PyImport_LAZY_ALL;
-        }
-        else {
-            lazy_mode = PyImport_LAZY_NONE;
-        }
-        if (PyImport_SetLazyImportsMode(lazy_mode) < 0) {
+    if (config->lazy_imports == 0) {
+        return _PyStatus_ERR("PyConfig.lazy_imports=0 is not supported");
+    }
+    if (config->lazy_imports == 1) {
+        if (PyImport_SetLazyImportsMode(PyImport_LAZY_ALL) < 0) {
             return _PyStatus_ERR("failed to set lazy imports mode");
         }
     }
index b2f33d4e809d265a9d73c11cd160f639a90ce8f6..b79ebf56371ff2adee89371db673d9ffb734e0fa 100644 (file)
@@ -2845,7 +2845,6 @@ Sets the global lazy imports mode.
 
 The mode parameter must be one of the following strings:
 - "all": All top-level imports become potentially lazy
-- "none": All lazy imports are suppressed (even explicitly marked ones)
 - "normal": Only explicitly marked imports (with 'lazy' keyword) are
   lazy
 
@@ -2856,12 +2855,12 @@ provided to sys.set_lazy_imports_filter
 
 static PyObject *
 sys_set_lazy_imports_impl(PyObject *module, PyObject *mode)
-/*[clinic end generated code: output=1ff34ba6c4feaf73 input=cb6df28a51844a31]*/
+/*[clinic end generated code: output=1ff34ba6c4feaf73 input=db3242f0ff6e5dcc]*/
 {
     PyImport_LazyImportsMode lazy_mode;
     if (!PyUnicode_Check(mode)) {
         PyErr_SetString(PyExc_TypeError,
-                        "mode must be a string: 'normal', 'all', or 'none'");
+                        "mode must be a string: 'normal' or 'all'");
         return NULL;
     }
     if (PyUnicode_CompareWithASCIIString(mode, "normal") == 0) {
@@ -2870,12 +2869,9 @@ sys_set_lazy_imports_impl(PyObject *module, PyObject *mode)
     else if (PyUnicode_CompareWithASCIIString(mode, "all") == 0) {
         lazy_mode = PyImport_LAZY_ALL;
     }
-    else if (PyUnicode_CompareWithASCIIString(mode, "none") == 0) {
-        lazy_mode = PyImport_LAZY_NONE;
-    }
     else {
         PyErr_SetString(PyExc_ValueError,
-                        "mode must be 'normal', 'all', or 'none'");
+                        "mode must be 'normal' or 'all'");
         return NULL;
     }
 
@@ -2891,22 +2887,19 @@ sys.get_lazy_imports
 Gets the global lazy imports mode.
 
 Returns "all" if all top level imports are potentially lazy.
-Returns "none" if all explicitly marked lazy imports are suppressed.
 Returns "normal" if only explicitly marked imports are lazy.
 
 [clinic start generated code]*/
 
 static PyObject *
 sys_get_lazy_imports_impl(PyObject *module)
-/*[clinic end generated code: output=4147dec48c51ae99 input=8cb574f1e4e3003c]*/
+/*[clinic end generated code: output=4147dec48c51ae99 input=6f8dd4f2c82893f2]*/
 {
     switch (PyImport_GetLazyImportsMode()) {
         case PyImport_LAZY_NORMAL:
             return PyUnicode_FromString("normal");
         case PyImport_LAZY_ALL:
             return PyUnicode_FromString("all");
-        case PyImport_LAZY_NONE:
-            return PyUnicode_FromString("none");
         default:
             PyErr_SetString(PyExc_RuntimeError, "unknown lazy imports mode");
             return NULL;