Skip to content

Commit 1e220b1

Browse files
authored
Don't suggest --install-types in daemon mode (#10508)
It doesn't work with mypy daemon. Fixes #10015.
1 parent 58aef05 commit 1e220b1

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

mypy/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2546,7 +2546,8 @@ def module_not_found(manager: BuildManager, line: int, caller_state: State,
25462546
blocker=True)
25472547
errors.raise_error()
25482548
else:
2549-
msg, notes = reason.error_message_templates()
2549+
daemon = manager.options.fine_grained_incremental
2550+
msg, notes = reason.error_message_templates(daemon)
25502551
pyver = '%d.%d' % manager.options.python_version
25512552
errors.report(line, 0, msg.format(module=target, pyver=pyver), code=codes.IMPORT)
25522553
top_level = target.partition('.')[0]

mypy/modulefinder.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ModuleNotFoundReason(Enum):
5959
# Stub PyPI package (typically types-pkgname) known to exist but not installed.
6060
STUBS_NOT_INSTALLED = 3
6161

62-
def error_message_templates(self) -> Tuple[str, List[str]]:
62+
def error_message_templates(self, daemon: bool) -> Tuple[str, List[str]]:
6363
doc_link = "See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports"
6464
if self is ModuleNotFoundReason.NOT_FOUND:
6565
msg = 'Cannot find implementation or library stub for module named "{module}"'
@@ -75,9 +75,11 @@ def error_message_templates(self) -> Tuple[str, List[str]]:
7575
msg = (
7676
'Library stubs not installed for "{module}" (or incompatible with Python {pyver})'
7777
)
78-
notes = ['Hint: "python3 -m pip install {stub_dist}"',
79-
'(or run "mypy --install-types" to install all missing stub packages)',
80-
doc_link]
78+
notes = ['Hint: "python3 -m pip install {stub_dist}"']
79+
if not daemon:
80+
notes.append(
81+
'(or run "mypy --install-types" to install all missing stub packages)')
82+
notes.append(doc_link)
8183
else:
8284
assert False
8385
return msg, notes

test-data/unit/fine-grained-modules.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,3 +2185,21 @@ x = 'x'
21852185

21862186
[out]
21872187
==
2188+
2189+
[case testLibraryStubsNotInstalled]
2190+
import a
2191+
[file a.py]
2192+
import waitress
2193+
[file a.py.2]
2194+
# nothing
2195+
[file a.py.3]
2196+
import pynamodb
2197+
[out]
2198+
a.py:1: error: Library stubs not installed for "waitress" (or incompatible with Python 3.6)
2199+
a.py:1: note: Hint: "python3 -m pip install types-waitress"
2200+
a.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
2201+
==
2202+
==
2203+
a.py:1: error: Library stubs not installed for "pynamodb" (or incompatible with Python 3.6)
2204+
a.py:1: note: Hint: "python3 -m pip install types-pynamodb"
2205+
a.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

0 commit comments

Comments
 (0)