Avoid crashing on invalid python executables #12812
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When an invalid python executable is passed to mypy, show an error message instead of crashing with a
FileNotFoundError
or some other exception.The implementation of the error raises a
CompileError
instead of using the normal error handling frommypy.errors.Errors
, similar to what we do for nonexistent files being passed to mypy:mypy/mypy/build.py
Lines 2058 to 2061 in 8e7e817
I used that approach because the relevant code didn't have access to an
Errors
instance and there probably isn't much reason to support continuing to check code when thepython_executable
is incorrect.Test Plan
I couldn't reproduce the crash in the test suite (I'm guessing that's because we don't try looking for site-packages in the test suite, but I haven't confirmed that), so I tested this manually by running
mypy empty.py --python-executable nonexistent
, where empty.py is an empty file.On master (8e7e817):
With this PR: