File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 1010import sys
1111import sysconfig
1212
13- if __name__ == '__main__' :
14- sys .path = sys .path [1 :] # we don't want to pick up mypy.types
15-
1613MYPY = False
1714if MYPY :
1815 from typing import List
@@ -29,10 +26,17 @@ def getsearchdirs():
2926 )
3027 stdlib = sysconfig .get_path ("stdlib" )
3128 stdlib_ext = os .path .join (stdlib , "lib-dynload" )
32- cwd = os .path .abspath (os .getcwd ())
33- excludes = set ([cwd , stdlib_zip , stdlib , stdlib_ext ])
34-
35- abs_sys_path = (os .path .abspath (p ) for p in sys .path )
29+ excludes = set ([stdlib_zip , stdlib , stdlib_ext ])
30+
31+ # Drop the first entry of sys.path
32+ # - If pyinfo.py is executed as a script (in a subprocess), this is the directory
33+ # containing pyinfo.py
34+ # - Otherwise, if mypy launched via console script, this is the directory of the script
35+ # - Otherwise, if mypy launched via python -m mypy, this is the current directory
36+ # In all cases, this is safe to drop
37+ # Note that mypy adds the cwd to SearchPaths.python_path, so we still find things on the
38+ # cwd consistently (the return value here sets SearchPaths.package_path)
39+ abs_sys_path = (os .path .abspath (p ) for p in sys .path [1 :])
3640 return [p for p in abs_sys_path if p not in excludes ]
3741
3842
You can’t perform that action at this time.
0 commit comments