Skip to content

Don't suggest --install-types in daemon mode #10508

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
merged 1 commit into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2546,7 +2546,8 @@ def module_not_found(manager: BuildManager, line: int, caller_state: State,
blocker=True)
errors.raise_error()
else:
msg, notes = reason.error_message_templates()
daemon = manager.options.fine_grained_incremental
msg, notes = reason.error_message_templates(daemon)
pyver = '%d.%d' % manager.options.python_version
errors.report(line, 0, msg.format(module=target, pyver=pyver), code=codes.IMPORT)
top_level = target.partition('.')[0]
Expand Down
10 changes: 6 additions & 4 deletions mypy/modulefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ModuleNotFoundReason(Enum):
# Stub PyPI package (typically types-pkgname) known to exist but not installed.
STUBS_NOT_INSTALLED = 3

def error_message_templates(self) -> Tuple[str, List[str]]:
def error_message_templates(self, daemon: bool) -> Tuple[str, List[str]]:
doc_link = "See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports"
if self is ModuleNotFoundReason.NOT_FOUND:
msg = 'Cannot find implementation or library stub for module named "{module}"'
Expand All @@ -75,9 +75,11 @@ def error_message_templates(self) -> Tuple[str, List[str]]:
msg = (
'Library stubs not installed for "{module}" (or incompatible with Python {pyver})'
)
notes = ['Hint: "python3 -m pip install {stub_dist}"',
'(or run "mypy --install-types" to install all missing stub packages)',
doc_link]
notes = ['Hint: "python3 -m pip install {stub_dist}"']
if not daemon:
notes.append(
'(or run "mypy --install-types" to install all missing stub packages)')
notes.append(doc_link)
else:
assert False
return msg, notes
Expand Down
18 changes: 18 additions & 0 deletions test-data/unit/fine-grained-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -2185,3 +2185,21 @@ x = 'x'

[out]
==

[case testLibraryStubsNotInstalled]
import a
[file a.py]
import waitress
[file a.py.2]
# nothing
[file a.py.3]
import pynamodb
[out]
a.py:1: error: Library stubs not installed for "waitress" (or incompatible with Python 3.6)
a.py:1: note: Hint: "python3 -m pip install types-waitress"
a.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
==
==
a.py:1: error: Library stubs not installed for "pynamodb" (or incompatible with Python 3.6)
a.py:1: note: Hint: "python3 -m pip install types-pynamodb"
a.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports