Repository: python/mypy

Issue:
Mypy daemon suggests using "mypy --install-types" but it doesn't work
Here's what happened:
```
$ dmypy run -- t/t.py
Daemon started
t/t.py:1: error: Library stubs not installed for "requests" (or incompatible with Python 3.8)
t/t.py:1: note: Hint: "python3 -m pip install types-requests"
t/t.py:1: note: (or run "mypy --install-types" to install all missing stub packages)
t/t.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 22 source files)
$ mypy --install-types
Error: no mypy cache directory (you must enable incremental mode)
```

We should either make `--install-types` work with the daemon or not suggest using it when using the daemon.


Discussion:
Experiencing the same problem within the VS code when running
![image](https://user-images.githubusercontent.com/24612001/108206585-e0413d80-7126-11eb-99b5-e0610fee8458.png)



 any news on the workaround/solution? 
@KantiCodes you're probably using a version of mypy that doesn't support the new option yet.
@JelleZijlstra thanks a lot :)

Resolving patch:
diff --git a/mypy/build.py b/mypy/build.py
--- a/mypy/build.py
+++ b/mypy/build.py
@@ -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]
diff --git a/mypy/modulefinder.py b/mypy/modulefinder.py
--- a/mypy/modulefinder.py
+++ b/mypy/modulefinder.py
@@ -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}"'
@@ -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


Test patch:
diff --git a/test-data/unit/fine-grained-modules.test b/test-data/unit/fine-grained-modules.test
--- a/test-data/unit/fine-grained-modules.test
+++ b/test-data/unit/fine-grained-modules.test
@@ -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