Skip to content

adding "--silent-imports" suggestion to error message #1419

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 2 commits into from
Apr 26, 2016
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
5 changes: 3 additions & 2 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,9 @@ def module_not_found(self, path: str, line: int, id: str) -> None:
self.errors.report(line, stub_msg, severity='note', only_once=True)
else:
self.errors.report(line, "Cannot find module named '{}'".format(id))
self.errors.report(line, "(Perhaps setting MYPYPATH would help)", severity='note',
only_once=True)
self.errors.report(line, '(Perhaps setting MYPYPATH '
'or using the "--silent-imports" flag would help)',
severity='note', only_once=True)

def report_file(self, file: MypyFile) -> None:
if self.source_set.is_source(file):
Expand Down
34 changes: 17 additions & 17 deletions mypy/test/data/check-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ import nonexistent
None + ''
[out]
main:1: error: Cannot find module named 'nonexistent'
main:1: note: (Perhaps setting MYPYPATH would help)
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
main:2: error: Unsupported left operand type for + (None)

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

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

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

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

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

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

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

[case testAccessingUnknownModule2]
import xyz, bar
xyz.foo()
bar()
[out]
main:1: error: Cannot find module named 'xyz'
main:1: note: (Perhaps setting MYPYPATH would help)
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
main:1: error: Cannot find module named 'bar'

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

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

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

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

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

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

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

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

[case testRelativeImports]
Expand Down
2 changes: 1 addition & 1 deletion mypy/test/data/check-python2.test
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ import asyncio
import Bastion
[out]
main:1: error: Cannot find module named 'asyncio'
main:1: note: (Perhaps setting MYPYPATH would help)
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
main:2: error: No library stub file for standard library module 'Bastion'
main:2: note: (Stub files are from https://github.com/python/typeshed)

Expand Down
6 changes: 3 additions & 3 deletions mypy/test/data/check-semanal-error.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ m.x = m.y
1() # E
[out]
main:1: error: Cannot find module named 'm'
main:1: note: (Perhaps setting MYPYPATH would help)
main:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
main:4: error: "int" not callable

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

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

Expand Down
2 changes: 1 addition & 1 deletion mypy/test/data/check-unreachable-code.test
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ else:
[builtins fixtures/bool.py]
[out]
main:6: error: Cannot find module named 'pow123'
main:6: note: (Perhaps setting MYPYPATH would help)
main:6: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)

[case testMypyConditional]
import typing
Expand Down
16 changes: 8 additions & 8 deletions mypy/test/data/semanal-errors.test
Original file line number Diff line number Diff line change
Expand Up @@ -231,21 +231,21 @@ import typing
import m
[out]
main:2: error: Cannot find module named 'm'
main:2: note: (Perhaps setting MYPYPATH would help)
main:2: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)

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

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

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

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

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

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

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

[case testBreakOutsideLoop]
break
Expand Down