@@ -261,34 +261,38 @@ def find_spec(
261
261
path : Optional [Sequence [Union [bytes , str ]]] = None ,
262
262
target : Optional [ModuleType ] = None
263
263
) -> Optional [importlib .machinery .ModuleSpec ]:
264
- if fullname .split ('.' , maxsplit = 1 )[0 ] in self ._top_level_modules :
265
- if self ._build_path in os .environ .get (MARKER , '' ).split (os .pathsep ):
266
- return None
267
- namespace = False
268
- tree = self ._rebuild ()
269
- parts = fullname .split ('.' )
270
-
271
- # look for a package
272
- package = tree .get (tuple (parts ))
273
- if isinstance (package , Node ):
274
- for loader , suffix in LOADERS :
275
- src = package .get ('__init__' + suffix )
276
- if isinstance (src , str ):
277
- return build_module_spec (loader , fullname , src , package )
278
- else :
279
- namespace = True
280
264
281
- # look for a module
265
+ if fullname .split ('.' , maxsplit = 1 )[0 ] not in self ._top_level_modules :
266
+ return None
267
+
268
+ if self ._build_path in os .environ .get (MARKER , '' ).split (os .pathsep ):
269
+ return None
270
+
271
+ namespace = False
272
+ tree = self ._rebuild ()
273
+ parts = fullname .split ('.' )
274
+
275
+ # look for a package
276
+ package = tree .get (tuple (parts ))
277
+ if isinstance (package , Node ):
282
278
for loader , suffix in LOADERS :
283
- src = tree .get (( * parts [: - 1 ], parts [ - 1 ] + suffix ) )
279
+ src = package .get ('__init__' + suffix )
284
280
if isinstance (src , str ):
285
- return build_module_spec (loader , fullname , src , None )
286
-
287
- # namespace
288
- if namespace :
289
- spec = importlib .machinery .ModuleSpec (fullname , None )
290
- spec .submodule_search_locations = []
291
- return spec
281
+ return build_module_spec (loader , fullname , src , package )
282
+ else :
283
+ namespace = True
284
+
285
+ # look for a module
286
+ for loader , suffix in LOADERS :
287
+ src = tree .get ((* parts [:- 1 ], parts [- 1 ] + suffix ))
288
+ if isinstance (src , str ):
289
+ return build_module_spec (loader , fullname , src , None )
290
+
291
+ # namespace
292
+ if namespace :
293
+ spec = importlib .machinery .ModuleSpec (fullname , None )
294
+ spec .submodule_search_locations = []
295
+ return spec
292
296
293
297
return None
294
298
0 commit comments