@@ -668,10 +668,13 @@ def mypy_path() -> list[str]:
668
668
def default_lib_path (
669
669
data_dir : str , pyversion : tuple [int , int ], custom_typeshed_dir : str | None
670
670
) -> list [str ]:
671
- """Return default standard library search paths."""
671
+ """Return default standard library search paths. Guaranteed to be normalised."""
672
+
673
+ data_dir = os .path .abspath (data_dir )
672
674
path : list [str ] = []
673
675
674
676
if custom_typeshed_dir :
677
+ custom_typeshed_dir = os .path .abspath (custom_typeshed_dir )
675
678
typeshed_dir = os .path .join (custom_typeshed_dir , "stdlib" )
676
679
mypy_extensions_dir = os .path .join (custom_typeshed_dir , "stubs" , "mypy-extensions" )
677
680
versions_file = os .path .join (typeshed_dir , "VERSIONS" )
@@ -711,7 +714,7 @@ def default_lib_path(
711
714
712
715
@functools .lru_cache (maxsize = None )
713
716
def get_search_dirs (python_executable : str | None ) -> tuple [list [str ], list [str ]]:
714
- """Find package directories for given python.
717
+ """Find package directories for given python. Guaranteed to return absolute paths.
715
718
716
719
This runs a subprocess call, which generates a list of the directories in sys.path.
717
720
To avoid repeatedly calling a subprocess (which can be slow!) we
@@ -773,6 +776,7 @@ def compute_search_paths(
773
776
root_dir = os .getenv ("MYPY_TEST_PREFIX" , None )
774
777
if not root_dir :
775
778
root_dir = os .path .dirname (os .path .dirname (__file__ ))
779
+ root_dir = os .path .abspath (root_dir )
776
780
lib_path .appendleft (os .path .join (root_dir , "test-data" , "unit" , "lib-stub" ))
777
781
# alt_lib_path is used by some tests to bypass the normal lib_path mechanics.
778
782
# If we don't have one, grab directories of source files.
@@ -829,6 +833,7 @@ def compute_search_paths(
829
833
return SearchPaths (
830
834
python_path = tuple (reversed (python_path )),
831
835
mypy_path = tuple (mypypath ),
836
+ # package_path and typeshed_path must be normalised and absolute via os.path.abspath
832
837
package_path = tuple (sys_path + site_packages ),
833
838
typeshed_path = tuple (lib_path ),
834
839
)
0 commit comments