Avoid crashing on invalid python executables#12812
Merged
JukkaL merged 1 commit intopython:masterfrom May 19, 2022
Merged
Conversation
When an invalid python executable is passed to mypy, show an error message instead of crashing.
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
JukkaL
approved these changes
May 19, 2022
Collaborator
JukkaL
left a comment
There was a problem hiding this comment.
Thanks! This is much more friendlier than showing a traceback.
JukkaL
pushed a commit
that referenced
this pull request
May 20, 2022
When an invalid python executable is passed to mypy, show an error message instead of crashing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
FileNotFoundErroror some other exception.The implementation of the error raises a
CompileErrorinstead 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
Errorsinstance and there probably isn't much reason to support continuing to check code when thepython_executableis 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: