Skip to content

Commit 7e15a0b

Browse files
Improve missing import message
1 parent 4510a0b commit 7e15a0b

19 files changed

+153
-153
lines changed

docs/source/error_code_list.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ Example:
484484

485485
.. code-block:: python
486486
487-
# Error: Cannot find module named 'acme' [import]
487+
# Error: Cannot find implementation or library stub for module named 'acme' [import]
488488
import acme
489489
490490
See :ref:`ignore-missing-imports` for how to work around these errors.

docs/source/existing_code.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ find or that don't have stub files:
4242

4343
.. code-block:: text
4444
45-
core/config.py:7: error: Cannot find module named 'frobnicate'
46-
core/model.py:9: error: Cannot find module named 'acme'
45+
core/config.py:7: error: Cannot find implementation or library stub for module named 'frobnicate'
46+
core/model.py:9: error: Cannot find implementation or library stub for module named 'acme'
4747
...
4848
4949
This is normal, and you can easily ignore these errors. For example,

docs/source/running_mypy.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ This can cause a lot of errors that look like the following::
135135

136136
main.py:1: error: No library stub file for standard library module 'antigravity'
137137
main.py:2: error: No library stub file for module 'flask'
138-
main.py:3: error: Cannot find module named 'this_module_does_not_exist'
138+
main.py:3: error: Cannot find implementation or library stub for module named 'this_module_does_not_exist'
139139

140140
There are several different things you can try doing, depending on the exact
141141
nature of the module.

mypy/build.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2436,7 +2436,7 @@ def module_not_found(manager: BuildManager, line: int, caller_state: State,
24362436
errors.report(line, 0, stub_msg, severity='note', only_once=True, code=codes.IMPORT)
24372437
else:
24382438
note = "See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports"
2439-
errors.report(line, 0, "Cannot find module named '{}'".format(target), code=codes.IMPORT)
2439+
errors.report(line, 0, "Cannot find implementation or library stub for module named '{}'".format(target), code=codes.IMPORT)
24402440
errors.report(line, 0, note, severity='note', only_once=True, code=codes.IMPORT)
24412441
errors.set_import_context(save_import_context)
24422442

mypy/test/testpep561.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class SimpleMsg(Enum):
5959

6060

6161
class NamespaceMsg(Enum):
62-
cfm_beta = ("{tempfile}:4: error: Cannot find module named "
62+
cfm_beta = ("{tempfile}:4: error: Cannot find implementation or library stub for module named "
6363
"'typedpkg_ns.ns.dne'")
6464
help_note = ('{tempfile}:4: note: See https://mypy.readthedocs.io/en/latest/'
6565
'running_mypy.html#missing-imports')

test-data/unit/check-errorcodes.test

+4-4
Original file line numberDiff line numberDiff line change
@@ -495,12 +495,12 @@ if int() is str(): # E: Non-overlapping identity check (left operand type: "int
495495
[case testErrorCodeMissingModule]
496496
from defusedxml import xyz # E: No library stub file for module 'defusedxml' [import] \
497497
# N: (Stub files are from https://github.com/python/typeshed)
498-
from nonexistent import foobar # E: Cannot find module named 'nonexistent' [import] \
498+
from nonexistent import foobar # E: Cannot find implementation or library stub for module named 'nonexistent' [import] \
499499
# N: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
500-
import nonexistent2 # E: Cannot find module named 'nonexistent2' [import]
501-
from nonexistent3 import * # E: Cannot find module named 'nonexistent3' [import]
500+
import nonexistent2 # E: Cannot find implementation or library stub for module named 'nonexistent2' [import]
501+
from nonexistent3 import * # E: Cannot find implementation or library stub for module named 'nonexistent3' [import]
502502
from pkg import bad # E: Module 'pkg' has no attribute 'bad' [attr-defined]
503-
from pkg.bad2 import bad3 # E: Cannot find module named 'pkg.bad2' [import]
503+
from pkg.bad2 import bad3 # E: Cannot find implementation or library stub for module named 'pkg.bad2' [import]
504504
[file pkg/__init__.py]
505505

506506
[case testErrorCodeAlreadyDefined]

test-data/unit/check-flags.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ main:2: note: (Using --follow-imports=error, module not passed on command line)
453453
[case testIgnoreMissingImportsFalse]
454454
from mod import x
455455
[out]
456-
main:1: error: Cannot find module named 'mod'
456+
main:1: error: Cannot find implementation or library stub for module named 'mod'
457457
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
458458

459459
[case testIgnoreMissingImportsTrue]
@@ -610,7 +610,7 @@ from missing import MyType
610610
def f(x: MyType) -> None:
611611
pass
612612
[out]
613-
main:2: error: Cannot find module named 'missing'
613+
main:2: error: Cannot find implementation or library stub for module named 'missing'
614614
main:2: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
615615
main:4: error: Argument 1 to "f" becomes "Any" due to an unfollowed import
616616

test-data/unit/check-incremental.test

+5-5
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,7 @@ x = 1
20852085
[rechecked n]
20862086
[stale]
20872087
[out2]
2088-
tmp/n.py:1: error: Cannot find module named 'm'
2088+
tmp/n.py:1: error: Cannot find implementation or library stub for module named 'm'
20892089
tmp/n.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
20902090

20912091
[case testDeleteFileWithinCycle]
@@ -3382,7 +3382,7 @@ import a
33823382
[out1]
33833383

33843384
[out2]
3385-
main:2: error: Cannot find module named 'a'
3385+
main:2: error: Cannot find implementation or library stub for module named 'a'
33863386
main:2: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
33873387

33883388
[case testIncrementalInheritanceAddAnnotation]
@@ -3525,7 +3525,7 @@ def f() -> None: pass
35253525
def f(x: int) -> None: pass
35263526
[out]
35273527
[out2]
3528-
main:1: error: Cannot find module named 'p.q'
3528+
main:1: error: Cannot find implementation or library stub for module named 'p.q'
35293529
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
35303530
[out3]
35313531
main:2: error: Too few arguments for "f"
@@ -4140,10 +4140,10 @@ def __getattr__(attr: str) -> Any: ...
41404140
# empty
41414141
[builtins fixtures/module.pyi]
41424142
[out]
4143-
tmp/c.py:1: error: Cannot find module named 'a.b.c'
4143+
tmp/c.py:1: error: Cannot find implementation or library stub for module named 'a.b.c'
41444144
tmp/c.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
41454145
[out2]
4146-
tmp/c.py:1: error: Cannot find module named 'a.b.c'
4146+
tmp/c.py:1: error: Cannot find implementation or library stub for module named 'a.b.c'
41474147
tmp/c.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
41484148

41494149
[case testAddedMissingStubs]

test-data/unit/check-literal.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ func(f) # E: Argument 1 to "func" has incompatible type "Union[Literal['foo'],
851851
[case testLiteralDisallowAny]
852852
from typing import Any
853853
from typing_extensions import Literal
854-
from missing_module import BadAlias # E: Cannot find module named 'missing_module' \
854+
from missing_module import BadAlias # E: Cannot find implementation or library stub for module named 'missing_module' \
855855
# N: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
856856

857857
a: Literal[Any] # E: Parameter 1 of Literal[...] cannot be of type "Any"

test-data/unit/check-modules.test

+27-27
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ else:
208208
import nonexistent
209209
None + ''
210210
[out]
211-
main:1: error: Cannot find module named 'nonexistent'
211+
main:1: error: Cannot find implementation or library stub for module named 'nonexistent'
212212
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
213213
main:2: error: Unsupported left operand type for + ("None")
214214

@@ -220,7 +220,7 @@ m.x = ''
220220
[file m.py]
221221
x = 1
222222
[out]
223-
main:1: error: Cannot find module named 'nonexistent'
223+
main:1: error: Cannot find implementation or library stub for module named 'nonexistent'
224224
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
225225
main:2: error: Unsupported left operand type for + ("None")
226226
main:4: error: Incompatible types in assignment (expression has type "str", variable has type "int")
@@ -233,7 +233,7 @@ m.x = ''
233233
[file m.py]
234234
x = 1
235235
[out]
236-
main:1: error: Cannot find module named 'nonexistent'
236+
main:1: error: Cannot find implementation or library stub for module named 'nonexistent'
237237
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
238238
main:2: error: Unsupported left operand type for + ("None")
239239
main:4: error: Incompatible types in assignment (expression has type "str", variable has type "int")
@@ -242,32 +242,32 @@ main:4: error: Incompatible types in assignment (expression has type "str", vari
242242
import nonexistent, another
243243
None + ''
244244
[out]
245-
main:1: error: Cannot find module named 'nonexistent'
245+
main:1: error: Cannot find implementation or library stub for module named 'nonexistent'
246246
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
247-
main:1: error: Cannot find module named 'another'
247+
main:1: error: Cannot find implementation or library stub for module named 'another'
248248
main:2: error: Unsupported left operand type for + ("None")
249249

250250
[case testTypeCheckWithUnknownModule5]
251251
import nonexistent as x
252252
None + ''
253253
[out]
254-
main:1: error: Cannot find module named 'nonexistent'
254+
main:1: error: Cannot find implementation or library stub for module named 'nonexistent'
255255
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
256256
main:2: error: Unsupported left operand type for + ("None")
257257

258258
[case testTypeCheckWithUnknownModuleUsingFromImport]
259259
from nonexistent import x
260260
None + ''
261261
[out]
262-
main:1: error: Cannot find module named 'nonexistent'
262+
main:1: error: Cannot find implementation or library stub for module named 'nonexistent'
263263
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
264264
main:2: error: Unsupported left operand type for + ("None")
265265

266266
[case testTypeCheckWithUnknownModuleUsingImportStar]
267267
from nonexistent import *
268268
None + ''
269269
[out]
270-
main:1: error: Cannot find module named 'nonexistent'
270+
main:1: error: Cannot find implementation or library stub for module named 'nonexistent'
271271
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
272272
main:2: error: Unsupported left operand type for + ("None")
273273

@@ -276,24 +276,24 @@ import xyz
276276
xyz.foo()
277277
xyz()
278278
[out]
279-
main:1: error: Cannot find module named 'xyz'
279+
main:1: error: Cannot find implementation or library stub for module named 'xyz'
280280
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
281281

282282
[case testAccessingUnknownModule2]
283283
import xyz, bar
284284
xyz.foo()
285285
bar()
286286
[out]
287-
main:1: error: Cannot find module named 'xyz'
287+
main:1: error: Cannot find implementation or library stub for module named 'xyz'
288288
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
289-
main:1: error: Cannot find module named 'bar'
289+
main:1: error: Cannot find implementation or library stub for module named 'bar'
290290

291291
[case testAccessingUnknownModule3]
292292
import xyz as z
293293
xyz.foo()
294294
z()
295295
[out]
296-
main:1: error: Cannot find module named 'xyz'
296+
main:1: error: Cannot find implementation or library stub for module named 'xyz'
297297
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
298298
main:2: error: Name 'xyz' is not defined
299299

@@ -302,14 +302,14 @@ from xyz import y, z
302302
y.foo()
303303
z()
304304
[out]
305-
main:1: error: Cannot find module named 'xyz'
305+
main:1: error: Cannot find implementation or library stub for module named 'xyz'
306306
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
307307

308308
[case testAccessingNameImportedFromUnknownModule2]
309309
from xyz import *
310310
y
311311
[out]
312-
main:1: error: Cannot find module named 'xyz'
312+
main:1: error: Cannot find implementation or library stub for module named 'xyz'
313313
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
314314
main:2: error: Name 'y' is not defined
315315

@@ -318,14 +318,14 @@ from xyz import y as z
318318
y
319319
z
320320
[out]
321-
main:1: error: Cannot find module named 'xyz'
321+
main:1: error: Cannot find implementation or library stub for module named 'xyz'
322322
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
323323
main:2: error: Name 'y' is not defined
324324

325325
[case testUnknownModuleRedefinition]
326326
# Error messages differ with the new analyzer
327327

328-
import xab # E: Cannot find module named 'xab' # N: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
328+
import xab # E: Cannot find implementation or library stub for module named 'xab' # N: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
329329
def xab(): pass # E: Name 'xab' already defined (possibly by an import)
330330

331331
[case testAccessingUnknownModuleFromOtherModule]
@@ -336,7 +336,7 @@ x.z
336336
import nonexistent
337337
[builtins fixtures/module.pyi]
338338
[out]
339-
tmp/x.py:1: error: Cannot find module named 'nonexistent'
339+
tmp/x.py:1: error: Cannot find implementation or library stub for module named 'nonexistent'
340340
tmp/x.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
341341
main:3: error: Module has no attribute "z"
342342

@@ -346,7 +346,7 @@ def f():
346346
def foobar(): pass
347347
foobar('')
348348
[out]
349-
main:2: error: Cannot find module named 'foobar'
349+
main:2: error: Cannot find implementation or library stub for module named 'foobar'
350350
main:2: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
351351
main:4: error: Too many arguments for "foobar"
352352

@@ -356,7 +356,7 @@ def f():
356356
def x(): pass
357357
x('')
358358
[out]
359-
main:2: error: Cannot find module named 'foobar'
359+
main:2: error: Cannot find implementation or library stub for module named 'foobar'
360360
main:2: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
361361
main:4: error: Too many arguments for "x"
362362

@@ -2177,8 +2177,8 @@ import c
21772177

21782178
[out]
21792179
-- TODO: it would be better for this to be in the other order
2180-
tmp/b.py:1: error: Cannot find module named 'c'
2181-
main:1: error: Cannot find module named 'c'
2180+
tmp/b.py:1: error: Cannot find implementation or library stub for module named 'c'
2181+
main:1: error: Cannot find implementation or library stub for module named 'c'
21822182
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
21832183

21842184
[case testIndirectFromImportWithinCycle1]
@@ -2312,7 +2312,7 @@ from typing import Any
23122312
def __getattr__(attr: str) -> Any: ...
23132313
[builtins fixtures/module.pyi]
23142314
[out]
2315-
main:1: error: Cannot find module named 'a.b'
2315+
main:1: error: Cannot find implementation or library stub for module named 'a.b'
23162316
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
23172317

23182318
[case testModuleGetattrInit4]
@@ -2357,12 +2357,12 @@ def __getattr__(attr: str) -> Any: ...
23572357
# empty (i.e. complete subpackage)
23582358
[builtins fixtures/module.pyi]
23592359
[out]
2360-
main:1: error: Cannot find module named 'a.b.c.d'
2360+
main:1: error: Cannot find implementation or library stub for module named 'a.b.c.d'
23612361
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
2362-
main:1: error: Cannot find module named 'a.b.c'
2362+
main:1: error: Cannot find implementation or library stub for module named 'a.b.c'
23632363

23642364
[case testModuleGetattrInit8a]
2365-
import a.b.c # E: Cannot find module named 'a.b.c' # N: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
2365+
import a.b.c # E: Cannot find implementation or library stub for module named 'a.b.c' # N: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
23662366
import a.d # OK
23672367
[file a/__init__.pyi]
23682368
from typing import Any
@@ -2388,7 +2388,7 @@ def __getattr__(attr: str) -> Any: ...
23882388
ignore_missing_imports = True
23892389
[builtins fixtures/module.pyi]
23902390
[out]
2391-
main:3: error: Cannot find module named 'a.b.d'
2391+
main:3: error: Cannot find implementation or library stub for module named 'a.b.d'
23922392
main:3: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
23932393

23942394
[case testIndirectFromImportWithinCycleUsedAsBaseClass-skip]
@@ -2619,7 +2619,7 @@ from foo.bar import x
26192619
[file foo/bar.py]
26202620
x = 0
26212621
[out]
2622-
main:1: error: Cannot find module named 'foo.bar'
2622+
main:1: error: Cannot find implementation or library stub for module named 'foo.bar'
26232623
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
26242624

26252625
[case testNamespacePackage]

test-data/unit/check-python2.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ main:8: error: Argument 2 to "f" has incompatible type "int"; expected "Tuple[in
167167
import asyncio
168168
import Bastion
169169
[out]
170-
main:1: error: Cannot find module named 'asyncio'
170+
main:1: error: Cannot find implementation or library stub for module named 'asyncio'
171171
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
172172
main:2: error: No library stub file for standard library module 'Bastion'
173173
main:2: note: (Stub files are from https://github.com/python/typeshed)

test-data/unit/check-semanal-error.test

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ m.foo()
1818
m.x = m.y
1919
1() # E
2020
[out]
21-
main:1: error: Cannot find module named 'm'
21+
main:1: error: Cannot find implementation or library stub for module named 'm'
2222
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
2323
main:4: error: "int" not callable
2424

@@ -28,7 +28,7 @@ x.foo()
2828
x.a = x.b
2929
1() # E
3030
[out]
31-
main:1: error: Cannot find module named 'm'
31+
main:1: error: Cannot find implementation or library stub for module named 'm'
3232
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
3333
main:4: error: "int" not callable
3434

@@ -37,7 +37,7 @@ from m import * # E
3737
x # E
3838
1() # E
3939
[out]
40-
main:1: error: Cannot find module named 'm'
40+
main:1: error: Cannot find implementation or library stub for module named 'm'
4141
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
4242
main:2: error: Name 'x' is not defined
4343
main:3: error: "int" not callable

0 commit comments

Comments
 (0)