Skip to content

Commit 2288371

Browse files
authored
Always show the cause of error in dmypy suggest (python#7680)
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.
1 parent 263ba7f commit 2288371

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

mypy/suggestions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,9 @@ def reload(self, state: State, check_errors: bool = False) -> List[str]:
536536
"""
537537
assert state.path is not None
538538
res = self.fgmanager.update([(state.id, state.path)], [])
539-
# if res:
540-
# print('\n'.join(res))
541539
if check_errors and res:
542-
raise SuggestionFailure("Error while trying to load %s" % state.id)
540+
# TODO: apply color and formatting to error messages?
541+
raise SuggestionFailure("Error while processing %s:\n" % state.id + '\n'.join(res))
543542
return res
544543

545544
def ensure_loaded(self, state: State, force: bool = False) -> MypyFile:

test-data/unit/daemon.test

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,28 @@ from foo import foo
255255
def bar() -> None:
256256
x = foo('abc') # type: str
257257
foo(arg='xyz')
258+
259+
[case testDaemonSuggestErrorsShown]
260+
$ dmypy start --log-file log.txt -- --follow-imports=error --no-error-summary
261+
Daemon started
262+
$ dmypy check foo.py
263+
$ dmypy suggest tmp/foo.py:1
264+
() -> int
265+
$ {python} -c "import shutil; shutil.copy('foo.py.2', 'foo.py')"
266+
$ dmypy suggest tmp/foo.py:4
267+
Error while processing foo:
268+
foo.py:3: error: Unsupported operand types for + ("int" and "str")
269+
== Return code: 2
270+
[file foo.py]
271+
def foo():
272+
return 0
273+
foo() + 'no'
274+
def bar():
275+
return None
276+
[file foo.py.2]
277+
def foo() -> int:
278+
return 0
279+
foo() + 'no'
280+
def bar():
281+
return None
282+
[out]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy