-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Improve missing module error for subdirectories (#7405) #8927
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
Improve missing module error for subdirectories (#7405) #8927
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I'd say the note message may need some tweaks but generally this looks great!
Thanks, would be happy to take any suggestions on the wording of the message! |
mypy/modulefinder.py
Outdated
def error_message_templates(self) -> Tuple[str, str]: | ||
if self is ModuleNotFoundReason.NOT_FOUND: | ||
msg = "Cannot find implementation or library stub for module named '{}'" | ||
note = "See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports" | ||
elif self is ModuleNotFoundReason.WRONG_WORKING_DIRECTORY: | ||
msg = "Cannot find implementation or library stub for module named '{}'" | ||
note = ("You may be running mypy in the wrong directory, " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some brainstorm: You may be running mypy in a subdirectory, mypy should be run in the package root directory
. @JukkaL may have better suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any suggestions on this message, or other changes that need to be made in order for this PR to be ready for merge @JukkaL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments. Overall this seems like a very useful thing to have.
mypy/test/testcmdline.py
Outdated
"testFailedImportCannotBeFoundInParent": "main/subdir", | ||
"testImportInParentButNoInit": "main/subdir", | ||
"testFailedImportCanBeFoundInParentsParent": "main/subdir1/subdir2", | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer having a way of specifying this in the test case, as this is more fragile (consider what happens if one of the test cases is renamed). For example, this could be specified via # cwd: main/subdir
in the test case description, similar to how we have # cmd: ...
and similar. This would also make it easier to understand what the test cases are testing exactly.
This is not absolutely essential, but it would be nice to have. If you decide not to implement this, please add a comment to each test case that describes the working directory and mentions custom_working_dir
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added # cwd: ...
to testcmdline.py
👍
[file main/__init__.py] | ||
[out] | ||
main.py:1: error: Cannot find implementation or library stub for module named 'wrongdir' | ||
main.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Command line tests are quite expensive to run. Could you reduce the number of test cases to 2, for example? Maybe you can combine tested features.
e663f72
to
6c145c1
Compare
6c145c1
to
bf705b3
Compare
Thanks for the review @JukkaL! I addressed your comments, and used @TH3CHARLie's suggestion for the error message. Let me know if there's any more work that needs to be done on this PR! |
Fixes #7405