Skip to content

Commit

Permalink
Always show the cause of error in dmypy suggest (#7680)
Browse files Browse the repository at this point in the history
This PR prints the type errors that prevented `dmypy suggest` from running. Since this will be mostly used by interactive tools, I don't pipe the errors though normal formatting and colors, but if you think it makes sense, then I can do this.
  • Loading branch information
ilevkivskyi committed Oct 10, 2019
1 parent 263ba7f commit 2288371
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
5 changes: 2 additions & 3 deletions mypy/suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,9 @@ def reload(self, state: State, check_errors: bool = False) -> List[str]:
"""
assert state.path is not None
res = self.fgmanager.update([(state.id, state.path)], [])
# if res:
# print('\n'.join(res))
if check_errors and res:
raise SuggestionFailure("Error while trying to load %s" % state.id)
# TODO: apply color and formatting to error messages?
raise SuggestionFailure("Error while processing %s:\n" % state.id + '\n'.join(res))
return res

def ensure_loaded(self, state: State, force: bool = False) -> MypyFile:
Expand Down
25 changes: 25 additions & 0 deletions test-data/unit/daemon.test
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,28 @@ from foo import foo
def bar() -> None:
x = foo('abc') # type: str
foo(arg='xyz')

[case testDaemonSuggestErrorsShown]
$ dmypy start --log-file log.txt -- --follow-imports=error --no-error-summary
Daemon started
$ dmypy check foo.py
$ dmypy suggest tmp/foo.py:1
() -> int
$ {python} -c "import shutil; shutil.copy('foo.py.2', 'foo.py')"
$ dmypy suggest tmp/foo.py:4
Error while processing foo:
foo.py:3: error: Unsupported operand types for + ("int" and "str")
== Return code: 2
[file foo.py]
def foo():
return 0
foo() + 'no'
def bar():
return None
[file foo.py.2]
def foo() -> int:
return 0
foo() + 'no'
def bar():
return None
[out]

0 comments on commit 2288371

Please sign in to comment.