Skip to content

Commit f186103

Browse files
samuelcolvingvanrossum
authored andcommitted
adding "--silent-imports" suggestion to error message (#1419)
as suggested in #1339 alter module_not_found suggestion to "(Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)"
1 parent d395b0c commit f186103

File tree

6 files changed

+33
-32
lines changed

6 files changed

+33
-32
lines changed

mypy/build.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,9 @@ def module_not_found(self, path: str, line: int, id: str) -> None:
464464
self.errors.report(line, stub_msg, severity='note', only_once=True)
465465
else:
466466
self.errors.report(line, "Cannot find module named '{}'".format(id))
467-
self.errors.report(line, "(Perhaps setting MYPYPATH would help)", severity='note',
468-
only_once=True)
467+
self.errors.report(line, '(Perhaps setting MYPYPATH '
468+
'or using the "--silent-imports" flag would help)',
469+
severity='note', only_once=True)
469470

470471
def report_file(self, file: MypyFile) -> None:
471472
if self.source_set.is_source(file):

mypy/test/data/check-modules.test

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ import nonexistent
203203
None + ''
204204
[out]
205205
main:1: error: Cannot find module named 'nonexistent'
206-
main:1: note: (Perhaps setting MYPYPATH would help)
206+
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
207207
main:2: error: Unsupported left operand type for + (None)
208208

209209
[case testTypeCheckWithUnknownModule2]
@@ -215,7 +215,7 @@ m.x = ''
215215
x = 1
216216
[out]
217217
main:1: error: Cannot find module named 'nonexistent'
218-
main:1: note: (Perhaps setting MYPYPATH would help)
218+
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
219219
main:2: error: Unsupported left operand type for + (None)
220220
main:4: error: Incompatible types in assignment (expression has type "str", variable has type "int")
221221

@@ -228,7 +228,7 @@ m.x = ''
228228
x = 1
229229
[out]
230230
main:1: error: Cannot find module named 'nonexistent'
231-
main:1: note: (Perhaps setting MYPYPATH would help)
231+
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
232232
main:2: error: Unsupported left operand type for + (None)
233233
main:4: error: Incompatible types in assignment (expression has type "str", variable has type "int")
234234

@@ -237,7 +237,7 @@ import nonexistent, another
237237
None + ''
238238
[out]
239239
main:1: error: Cannot find module named 'nonexistent'
240-
main:1: note: (Perhaps setting MYPYPATH would help)
240+
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
241241
main:1: error: Cannot find module named 'another'
242242
main:2: error: Unsupported left operand type for + (None)
243243

@@ -246,23 +246,23 @@ import nonexistent as x
246246
None + ''
247247
[out]
248248
main:1: error: Cannot find module named 'nonexistent'
249-
main:1: note: (Perhaps setting MYPYPATH would help)
249+
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
250250
main:2: error: Unsupported left operand type for + (None)
251251

252252
[case testTypeCheckWithUnknownModuleUsingFromImport]
253253
from nonexistent import x
254254
None + ''
255255
[out]
256256
main:1: error: Cannot find module named 'nonexistent'
257-
main:1: note: (Perhaps setting MYPYPATH would help)
257+
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
258258
main:2: error: Unsupported left operand type for + (None)
259259

260260
[case testTypeCheckWithUnknownModuleUsingImportStar]
261261
from nonexistent import *
262262
None + ''
263263
[out]
264264
main:1: error: Cannot find module named 'nonexistent'
265-
main:1: note: (Perhaps setting MYPYPATH would help)
265+
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
266266
main:2: error: Unsupported left operand type for + (None)
267267

268268
[case testAccessingUnknownModule]
@@ -271,15 +271,15 @@ xyz.foo()
271271
xyz()
272272
[out]
273273
main:1: error: Cannot find module named 'xyz'
274-
main:1: note: (Perhaps setting MYPYPATH would help)
274+
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
275275

276276
[case testAccessingUnknownModule2]
277277
import xyz, bar
278278
xyz.foo()
279279
bar()
280280
[out]
281281
main:1: error: Cannot find module named 'xyz'
282-
main:1: note: (Perhaps setting MYPYPATH would help)
282+
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
283283
main:1: error: Cannot find module named 'bar'
284284

285285
[case testAccessingUnknownModule3]
@@ -288,7 +288,7 @@ xyz.foo()
288288
z()
289289
[out]
290290
main:1: error: Cannot find module named 'xyz'
291-
main:1: note: (Perhaps setting MYPYPATH would help)
291+
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
292292
main:2: error: Name 'xyz' is not defined
293293

294294
[case testAccessingNameImportedFromUnknownModule]
@@ -297,14 +297,14 @@ y.foo()
297297
z()
298298
[out]
299299
main:1: error: Cannot find module named 'xyz'
300-
main:1: note: (Perhaps setting MYPYPATH would help)
300+
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
301301

302302
[case testAccessingNameImportedFromUnknownModule2]
303303
from xyz import *
304304
y
305305
[out]
306306
main:1: error: Cannot find module named 'xyz'
307-
main:1: note: (Perhaps setting MYPYPATH would help)
307+
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
308308
main:2: error: Name 'y' is not defined
309309

310310
[case testAccessingNameImportedFromUnknownModule3]
@@ -313,15 +313,15 @@ y
313313
z
314314
[out]
315315
main:1: error: Cannot find module named 'xyz'
316-
main:1: note: (Perhaps setting MYPYPATH would help)
316+
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
317317
main:2: error: Name 'y' is not defined
318318

319319
[case testUnknownModuleRedefinition]
320320
import xab
321321
def xab(): pass
322322
[out]
323323
main:1: error: Cannot find module named 'xab'
324-
main:1: note: (Perhaps setting MYPYPATH would help)
324+
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
325325

326326
[case testAccessingUnknownModuleFromOtherModule]
327327
import x
@@ -333,7 +333,7 @@ import nonexistent
333333
[out]
334334
main:1: note: In module imported here:
335335
tmp/x.py:1: error: Cannot find module named 'nonexistent'
336-
tmp/x.py:1: note: (Perhaps setting MYPYPATH would help)
336+
tmp/x.py:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
337337
main:3: error: "module" has no attribute "z"
338338

339339
[case testUnknownModuleImportedWithinFunction]
@@ -343,7 +343,7 @@ def foobar(): pass
343343
foobar('')
344344
[out]
345345
main:2: error: Cannot find module named 'foobar'
346-
main:2: note: (Perhaps setting MYPYPATH would help)
346+
main:2: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
347347
main:4: error: Too many arguments for "foobar"
348348

349349
[case testUnknownModuleImportedWithinFunction2]
@@ -353,7 +353,7 @@ def x(): pass
353353
x('')
354354
[out]
355355
main:2: error: Cannot find module named 'foobar'
356-
main:2: note: (Perhaps setting MYPYPATH would help)
356+
main:2: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
357357
main:4: error: Too many arguments for "x"
358358

359359
[case testRelativeImports]

mypy/test/data/check-python2.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ import asyncio
136136
import Bastion
137137
[out]
138138
main:1: error: Cannot find module named 'asyncio'
139-
main:1: note: (Perhaps setting MYPYPATH would help)
139+
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
140140
main:2: error: No library stub file for standard library module 'Bastion'
141141
main:2: note: (Stub files are from https://github.com/python/typeshed)
142142

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ m.x = m.y
1919
1() # E
2020
[out]
2121
main:1: error: Cannot find module named 'm'
22-
main:1: note: (Perhaps setting MYPYPATH would help)
22+
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
2323
main:4: error: "int" not callable
2424

2525
[case testMissingModuleImport2]
@@ -29,7 +29,7 @@ x.a = x.b
2929
1() # E
3030
[out]
3131
main:1: error: Cannot find module named 'm'
32-
main:1: note: (Perhaps setting MYPYPATH would help)
32+
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
3333
main:4: error: "int" not callable
3434

3535
[case testMissingModuleImport3]
@@ -38,7 +38,7 @@ x # E
3838
1() # E
3939
[out]
4040
main:1: error: Cannot find module named 'm'
41-
main:1: note: (Perhaps setting MYPYPATH would help)
41+
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
4242
main:2: error: Name 'x' is not defined
4343
main:3: error: "int" not callable
4444

mypy/test/data/check-unreachable-code.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ else:
7979
[builtins fixtures/bool.py]
8080
[out]
8181
main:6: error: Cannot find module named 'pow123'
82-
main:6: note: (Perhaps setting MYPYPATH would help)
82+
main:6: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
8383

8484
[case testMypyConditional]
8585
import typing

mypy/test/data/semanal-errors.test

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,21 +231,21 @@ import typing
231231
import m
232232
[out]
233233
main:2: error: Cannot find module named 'm'
234-
main:2: note: (Perhaps setting MYPYPATH would help)
234+
main:2: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
235235

236236
[case testMissingModule2]
237237
import typing
238238
from m import x
239239
[out]
240240
main:2: error: Cannot find module named 'm'
241-
main:2: note: (Perhaps setting MYPYPATH would help)
241+
main:2: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
242242

243243
[case testMissingModule3]
244244
import typing
245245
from m import *
246246
[out]
247247
main:2: error: Cannot find module named 'm'
248-
main:2: note: (Perhaps setting MYPYPATH would help)
248+
main:2: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
249249

250250
[case testMissingModuleRelativeImport]
251251
import typing
@@ -255,7 +255,7 @@ from .x import y
255255
[out]
256256
main:2: note: In module imported here:
257257
tmp/m/__init__.py:1: error: Cannot find module named 'm.x'
258-
tmp/m/__init__.py:1: note: (Perhaps setting MYPYPATH would help)
258+
tmp/m/__init__.py:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
259259

260260
[case testMissingModuleRelativeImport2]
261261
import typing
@@ -266,7 +266,7 @@ from .x import y
266266
[out]
267267
main:2: note: In module imported here:
268268
tmp/m/a.py:1: error: Cannot find module named 'm.x'
269-
tmp/m/a.py:1: note: (Perhaps setting MYPYPATH would help)
269+
tmp/m/a.py:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
270270

271271
[case testModuleNotImported]
272272
import typing
@@ -317,15 +317,15 @@ import typing
317317
import m.n
318318
[out]
319319
main:2: error: Cannot find module named 'm.n'
320-
main:2: note: (Perhaps setting MYPYPATH would help)
320+
main:2: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
321321

322322
[case testMissingPackage]
323323
import typing
324324
from m.n import x
325325
from a.b import *
326326
[out]
327327
main:2: error: Cannot find module named 'm.n'
328-
main:2: note: (Perhaps setting MYPYPATH would help)
328+
main:2: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
329329
main:3: error: Cannot find module named 'a.b'
330330

331331
[case testErrorInImportedModule]
@@ -358,7 +358,7 @@ m.n.x
358358
x = 1
359359
[out]
360360
main:2: error: Cannot find module named 'm.n'
361-
main:2: note: (Perhaps setting MYPYPATH would help)
361+
main:2: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
362362

363363
[case testBreakOutsideLoop]
364364
break

0 commit comments

Comments
 (0)