Skip to content

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

Merged

Conversation

ethan-leba
Copy link
Contributor

@ethan-leba ethan-leba commented May 31, 2020

Fixes #7405

@ethan-leba ethan-leba marked this pull request as ready for review May 31, 2020 15:03
Copy link
Collaborator

@TH3CHARLie TH3CHARLie left a 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!

@ethan-leba
Copy link
Contributor Author

Thanks, would be happy to take any suggestions on the wording of the message!

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, "
Copy link
Collaborator

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

@JukkaL JukkaL left a 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.

"testFailedImportCannotBeFoundInParent": "main/subdir",
"testImportInParentButNoInit": "main/subdir",
"testFailedImportCanBeFoundInParentsParent": "main/subdir1/subdir2",
}
Copy link
Collaborator

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.

Copy link
Contributor Author

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
Copy link
Collaborator

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.

@ethan-leba ethan-leba force-pushed the eleba/better-module-messages branch 2 times, most recently from e663f72 to 6c145c1 Compare June 23, 2020 20:12
@ethan-leba ethan-leba force-pushed the eleba/better-module-messages branch from 6c145c1 to bf705b3 Compare June 23, 2020 20:38
@ethan-leba
Copy link
Contributor Author

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!

@hauntsaninja hauntsaninja merged commit fd99544 into python:master Aug 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explain that mypy should be run in the package root directory
4 participants