Content-Length: 288085 | pFad | http://github.com/python/cpython/commit/8ba32ec7a584d9d306a7de7326cacb4cde8ba252

71 gh-144957: Add test for lazy imports with __getattr__ · python/cpython@8ba32ec · GitHub
Skip to content

Commit 8ba32ec

Browse files
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.
1 parent 94d0199 commit 8ba32ec

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Lib/test/test_import/test_lazy_imports.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ def test_basic_used(self):
8585
import test.test_import.data.lazy_imports.basic_used
8686
self.assertIn("test.test_import.data.lazy_imports.basic2", sys.modules)
8787

88+
def test_lazy_import_with_getattr(self):
89+
"""Lazy imports work with module __getattr__ (gh-144957)."""
90+
code = textwrap.dedent("""
91+
import sys
92+
sys.set_lazy_imports("normal")
93+
lazy from typing import Match
94+
print(Match)
95+
""")
96+
result = subprocess.run(
97+
[sys.executable, "-c", code],
98+
capture_output=True,
99+
text=True
100+
)
101+
self.assertEqual(result.returncode, 0, result.stderr)
102+
self.assertIn("typing.Match", result.stdout)
103+
88104

89105
class GlobalLazyImportModeTests(unittest.TestCase):
90106
"""Tests for sys.set_lazy_imports() global mode control."""

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python/cpython/commit/8ba32ec7a584d9d306a7de7326cacb4cde8ba252

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy