Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[0.970 backport] Handle cwd correctly in pyinfo #13162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions 18 mypy/pyinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
import sys
import sysconfig

if __name__ == '__main__':
sys.path = sys.path[1:] # we don't want to pick up mypy.types

MYPY = False
if MYPY:
from typing import List
Expand All @@ -29,10 +26,17 @@ def getsearchdirs():
)
stdlib = sysconfig.get_path("stdlib")
stdlib_ext = os.path.join(stdlib, "lib-dynload")
cwd = os.path.abspath(os.getcwd())
excludes = set([cwd, stdlib_zip, stdlib, stdlib_ext])

abs_sys_path = (os.path.abspath(p) for p in sys.path)
excludes = set([stdlib_zip, stdlib, stdlib_ext])

# Drop the first entry of sys.path
# - If pyinfo.py is executed as a script (in a subprocess), this is the directory
# containing pyinfo.py
# - Otherwise, if mypy launched via console script, this is the directory of the script
# - Otherwise, if mypy launched via python -m mypy, this is the current directory
# In all cases, this is safe to drop
# Note that mypy adds the cwd to SearchPaths.python_path, so we still find things on the
# cwd consistently (the return value here sets SearchPaths.package_path)
abs_sys_path = (os.path.abspath(p) for p in sys.path[1:])
return [p for p in abs_sys_path if p not in excludes]


Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.