44
44
45
45
46
46
if sys .platform .startswith ("win" ):
47
- PY_SOURCE_EXTS = ("pyi" , "pyw" , "py" )
47
+ PY_SOURCE_EXTS = ("py" , "pyw" , "pyi" )
48
+ PY_SOURCE_EXTS_STUBS_FIRST = ("pyi" , "pyw" , "py" )
48
49
PY_COMPILED_EXTS = ("dll" , "pyd" )
49
50
else :
50
- PY_SOURCE_EXTS = ("pyi" , "py" )
51
+ PY_SOURCE_EXTS = ("py" , "pyi" )
52
+ PY_SOURCE_EXTS_STUBS_FIRST = ("pyi" , "py" )
51
53
PY_COMPILED_EXTS = ("so" ,)
52
54
53
55
@@ -484,7 +486,9 @@ def get_module_files(
484
486
return files
485
487
486
488
487
- def get_source_file (filename : str , include_no_ext : bool = False ) -> str :
489
+ def get_source_file (
490
+ filename : str , include_no_ext : bool = False , prefer_stubs : bool = False
491
+ ) -> str :
488
492
"""Given a python module's file name return the matching source file
489
493
name (the filename will be returned identically if it's already an
490
494
absolute path to a python source file).
@@ -499,7 +503,7 @@ def get_source_file(filename: str, include_no_ext: bool = False) -> str:
499
503
base , orig_ext = os .path .splitext (filename )
500
504
if orig_ext == ".pyi" and os .path .exists (f"{ base } { orig_ext } " ):
501
505
return f"{ base } { orig_ext } "
502
- for ext in PY_SOURCE_EXTS if "numpy" not in filename else reversed ( PY_SOURCE_EXTS ) :
506
+ for ext in PY_SOURCE_EXTS_STUBS_FIRST if prefer_stubs else PY_SOURCE_EXTS :
503
507
source_path = f"{ base } .{ ext } "
504
508
if os .path .exists (source_path ):
505
509
return source_path
@@ -671,8 +675,7 @@ def _has_init(directory: str) -> str | None:
671
675
else return None.
672
676
"""
673
677
mod_or_pack = os .path .join (directory , "__init__" )
674
- exts = reversed (PY_SOURCE_EXTS ) if "numpy" in directory else PY_SOURCE_EXTS
675
- for ext in (* exts , "pyc" , "pyo" ):
678
+ for ext in (* PY_SOURCE_EXTS , "pyc" , "pyo" ):
676
679
if os .path .exists (mod_or_pack + "." + ext ):
677
680
return mod_or_pack + "." + ext
678
681
return None
0 commit comments