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