Skip to content

Commit 96f33a7

Browse files
authored
Be more careful with sys.path editing in sitepkgs (#5265)
The `sitepkgs.py` script (support for PEP 561) was dropping `sys.path[0]`, but it is also imported by mypy itself, and this broke the `typed_ast` import when run under Bazel. Bazel puts very few things on `sys.path`, and `sys.path[0]` is important -- it has the dependencies. The editing is only necessary when it's run as an independent script (through `subprocess`) by the PEP 561 code, so we now check for `__name__ == '__main__'`.
1 parent ab2fb7b commit 96f33a7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

mypy/sitepkgs.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
possible.
88
"""
99

10-
import sys
11-
sys.path = sys.path[1:] # we don't want to pick up mypy.types
10+
if __name__ == '__main__':
11+
import sys
12+
sys.path = sys.path[1:] # we don't want to pick up mypy.types
13+
1214
from distutils.sysconfig import get_python_lib
1315
import site
16+
1417
MYPY = False
1518
if MYPY:
1619
from typing import List

0 commit comments

Comments
 (0)