Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add test for gh-117178
  • Loading branch information
effigies committed Mar 23, 2024
commit 367cdc13945a489f834767a56024f1cce1f77f72
17 changes: 17 additions & 0 deletions Lib/test/test_importlib/test_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,23 @@ def access_module():
# Or multiple load attempts
self.assertEqual(loader.load_count, 1)

def test_lazy_self_referential_modules(self):
# Directory modules with submodules that reference the parent can attempt to access
# the parent module during a load. Verify that this common pattern works with lazy loading.
# json is a good example in the stdlib.
json_modules = [name for name in sys.modules if name.startswith('json')]
with test_util.uncache(*json_modules):
# Standard lazy loading, unwrapped
spec = util.find_spec('json')
loader = util.LazyLoader(spec.loader)
spec.loader = loader
module = util.module_from_spec(spec)
sys.modules['json'] = module
loader.exec_module(module)

# Trigger load with attribute lookup
module.loads
Comment thread
effigies marked this conversation as resolved.
Outdated


if __name__ == '__main__':
unittest.main()