@@ -544,9 +544,7 @@ def import_path(
544
544
with contextlib .suppress (KeyError ):
545
545
return sys .modules [module_name ]
546
546
547
- mod = _import_module_using_spec (
548
- module_name , path , pkg_root , insert_modules = False
549
- )
547
+ mod = _import_module_using_spec (module_name , path , insert_modules = False )
550
548
if mod is not None :
551
549
return mod
552
550
@@ -556,9 +554,7 @@ def import_path(
556
554
with contextlib .suppress (KeyError ):
557
555
return sys .modules [module_name ]
558
556
559
- mod = _import_module_using_spec (
560
- module_name , path , path .parent , insert_modules = True
561
- )
557
+ mod = _import_module_using_spec (module_name , path , insert_modules = True )
562
558
if mod is None :
563
559
raise ImportError (f"Can't find module { module_name } at location { path } " )
564
560
return mod
@@ -611,7 +607,7 @@ def import_path(
611
607
612
608
613
609
def _import_module_using_spec (
614
- module_name : str , module_path : Path , module_location : Path , * , insert_modules : bool
610
+ module_name : str , module_path : Path , * , insert_modules : bool
615
611
) -> Optional [ModuleType ]:
616
612
"""
617
613
Tries to import a module by its canonical name, path to the .py file, and its
@@ -628,7 +624,7 @@ def _import_module_using_spec(
628
624
# Checking with sys.meta_path first in case one of its hooks can import this module,
629
625
# such as our own assertion-rewrite hook.
630
626
for meta_importer in sys .meta_path :
631
- spec = meta_importer .find_spec (module_name , [str (module_location )])
627
+ spec = meta_importer .find_spec (module_name , [str (module_path . parent )])
632
628
if spec_matches_module_path (spec , module_path ):
633
629
break
634
630
else :
0 commit comments