From 94d0199da0f81a8a20cd74fb3f9a8c88134149f6 Mon Sep 17 00:00:00 2001 From: Gouri Jain Date: Fri, 27 Feb 2026 22:37:27 +0530 Subject: [PATCH 1/2] Move __cached__ deprecation notice to its own attribute section and clean up __file__ docs --- Doc/reference/datamodel.rst | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 27aedfa878af9a..ec2e4cefb6629a 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1084,14 +1084,12 @@ this approach. :ref:`import system ` may opt to leave it unset if it has no semantic meaning (for example, a module loaded from a database). - .. deprecated-removed:: 3.13 3.15 - Setting ``__cached__`` on a module while failing to set - :attr:`!__spec__.cached` is deprecated. In Python 3.15, - ``__cached__`` will cease to be set or taken into consideration by - the import system or standard library. +.. attribute:: module.__cached__ + + The ``__cached__`` attribute stores the path to the compiled byte‑code file for a module. + It is deprecated and will be removed in Python 3.15. + - .. versionchanged:: 3.15 - ``__cached__`` is no longer set. Other writable attributes on module objects ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 8ba32ec7a584d9d306a7de7326cacb4cde8ba252 Mon Sep 17 00:00:00 2001 From: Gouri Jain Date: Fri, 27 Feb 2026 23:47:31 +0530 Subject: [PATCH 2/2] gh-144957: Add test for lazy imports with __getattr__ Adds regression test to verify lazy imports work correctly with modules that use __getattr__ for dynamic attributes (e.g. typing.Match). The issue appears to be already fixed in current main branch. --- Lib/test/test_import/test_lazy_imports.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Lib/test/test_import/test_lazy_imports.py b/Lib/test/test_import/test_lazy_imports.py index d4df772d2034d9..6241188a422015 100644 --- a/Lib/test/test_import/test_lazy_imports.py +++ b/Lib/test/test_import/test_lazy_imports.py @@ -85,6 +85,22 @@ def test_basic_used(self): import test.test_import.data.lazy_imports.basic_used self.assertIn("test.test_import.data.lazy_imports.basic2", sys.modules) + def test_lazy_import_with_getattr(self): + """Lazy imports work with module __getattr__ (gh-144957).""" + code = textwrap.dedent(""" + import sys + sys.set_lazy_imports("normal") + lazy from typing import Match + print(Match) + """) + result = subprocess.run( + [sys.executable, "-c", code], + capture_output=True, + text=True + ) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertIn("typing.Match", result.stdout) + class GlobalLazyImportModeTests(unittest.TestCase): """Tests for sys.set_lazy_imports() global mode control."""