File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -178,6 +178,23 @@ def access_module():
178
178
# Or multiple load attempts
179
179
self .assertEqual (loader .load_count , 1 )
180
180
181
+ def test_lazy_self_referential_modules (self ):
182
+ # Directory modules with submodules that reference the parent can attempt to access
183
+ # the parent module during a load. Verify that this common pattern works with lazy loading.
184
+ # json is a good example in the stdlib.
185
+ json_modules = [name for name in sys .modules if name .startswith ('json' )]
186
+ with test_util .uncache (* json_modules ):
187
+ # Standard lazy loading, unwrapped
188
+ spec = util .find_spec ('json' )
189
+ loader = util .LazyLoader (spec .loader )
190
+ spec .loader = loader
191
+ module = util .module_from_spec (spec )
192
+ sys .modules ['json' ] = module
193
+ loader .exec_module (module )
194
+
195
+ # Trigger load with attribute lookup
196
+ module .loads
197
+
181
198
182
199
if __name__ == '__main__' :
183
200
unittest .main ()
You can’t perform that action at this time.
0 commit comments