Skip to content

Commit ebcb52c

Browse files
committed
Extend the module __getattr__ test and fix the NEWS entry markup
1 parent c83d220 commit ebcb52c

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎Lib/test/test_lazy_import/__init__.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,11 @@ def test_from_import_with_imported_module_getattr(self):
172172
def test_module_getattr_does_not_shadow_own_lazy_import(self):
173173
"""Module __getattr__ should not shadow the module's own lazy imports."""
174174
code = textwrap.dedent("""
175+
import types
175176
import test.test_lazy_import.data.module_with_lazy_import_and_getattr as mod
176177
assert mod.basic2.__name__ == "test.test_lazy_import.data.basic2"
178+
assert mod.f is mod.basic2.f
179+
assert not isinstance(vars(mod)["basic2"], types.LazyImportType)
177180
assert mod.missing == "from_getattr:missing"
178181
""")
179182
assert_python_ok("-c", code)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
lazy import test.test_lazy_import.data.basic2 as basic2
2+
lazy from test.test_lazy_import.data.basic2 import f
23

34
def __getattr__(name):
45
return f"from_getattr:{name}"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Bug fix: module level `__getattr__` was obfuscating lazy imports from being reified.
1+
Module-level :meth:`~module.__getattr__` was called before a module's own
2+
lazy imports were resolved, so it could shadow them.

0 commit comments

Comments
 (0)