Skip to content
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

Fix pyinfo.py if PYTHONSAFEPATH is set #15110

Closed
hauntsaninja opened this issue Apr 24, 2023 · 2 comments · Fixed by #15122
Closed

Fix pyinfo.py if PYTHONSAFEPATH is set #15110

hauntsaninja opened this issue Apr 24, 2023 · 2 comments · Fixed by #15122
Labels
bug mypy got something wrong good-first-issue

Comments

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Apr 24, 2023

Python 3.11 adds a PYTHONSAFEPATH environment variable / -P flag that prevents script directory from ending up on PYTHONPATH: https://docs.python.org/3/using/cmdline.html#cmdoption-P

The logic in pyinfo.py will be broken if this environment variable is set.

The best fix is probably to set the environment variable when calling pyinfo in a subprocess on Python 3.11 and newer. This happens in modulefinder.py. We can then only do the sys.path hackery in pyinfo.py on older Python versions

@hauntsaninja hauntsaninja added bug mypy got something wrong good-first-issue labels Apr 24, 2023
@fgrabowski
Copy link

Could you please assign this to me? I think I know how to fix it with the potential fix you described and I am new to open source.

@JelleZijlstra
Copy link
Member

We don't usually do assignments, but feel free to submit a PR!

JukkaL pushed a commit that referenced this issue Apr 25, 2023
Fixes #15110 

- Add PYTHONSAFEPATH="true" to call to subprocess in get_search_dirs()
- Check sys.version_info before modifying path in pyinfo.py 

To test, import mypy.modulefinder.get_search_dirs & run:
- get_search_dirs() with no args
- on Python 3.11, call get_search_dirs with an earlier version as
python_executable
- on Python < 3.11, call get_search_dirs with Python 3.11 as
python_executable

Expected:
- consistent results, no exceptions

Co-authored-by: eevel <eevel@weezel3.weezelnet>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong good-first-issue
Projects
None yet
3 participants