Skip to content
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
9 changes: 7 additions & 2 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,12 @@ def build_inner(

source_set = BuildSourceSet(sources)
cached_read = fscache.read
errors = Errors(options, read_source=lambda path: read_py_file(path, cached_read))
error_formatter = None if options.output is None else OUTPUT_CHOICES.get(options.output)
errors = Errors(
options,
read_source=lambda path: read_py_file(path, cached_read),
error_formatter=error_formatter,
)
# Record import errors so that they can be replayed by the workers.
if workers:
errors.global_watcher = True
Expand All @@ -516,7 +521,7 @@ def build_inner(
plugin=plugin,
plugins_snapshot=snapshot,
errors=errors,
error_formatter=None if options.output is None else OUTPUT_CHOICES.get(options.output),
error_formatter=error_formatter,
flush_errors=flush_errors,
fscache=fscache,
stdout=stdout,
Expand Down
6 changes: 5 additions & 1 deletion mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,15 @@ def __init__(
*,
read_source: Callable[[str], list[str] | None] | None = None,
hide_error_codes: bool | None = None,
error_formatter: ErrorFormatter | None = None,
) -> None:
self.options = options
self.hide_error_codes = (
hide_error_codes if hide_error_codes is not None else options.hide_error_codes
)
# We use fscache to read source code when showing snippets.
self.read_source = read_source
self.error_formatter = error_formatter
self.initialize()

def initialize(self) -> None:
Expand Down Expand Up @@ -1129,7 +1131,9 @@ def new_messages(self) -> list[str]:
for path in self.error_info_map.keys():
if path not in self.flushed_files:
error_tuples = self.file_messages(path)
msgs.extend(self.format_messages(path, error_tuples))
msgs.extend(
self.format_messages(path, error_tuples, formatter=self.error_formatter)
)
return msgs

def targets(self) -> set[str]:
Expand Down
7 changes: 7 additions & 0 deletions test-data/unit/outputjson.test
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ bar('42')
{"file": "main", "line": 12, "column": 12, "end_line": 12, "end_column": 15, "message": "Revealed type is \"Overload(def (), def (x: int))\"", "hint": null, "code": "misc", "severity": "note"}
{"file": "main", "line": 14, "column": 0, "end_line": 14, "end_column": 9, "message": "No overload variant of \"foo\" matches argument type \"str\"", "hint": "Possible overload variants:\n def foo() -> None\n def foo(x: int) -> None", "code": "call-overload", "severity": "error"}
{"file": "main", "line": 17, "column": 0, "end_line": 17, "end_column": 9, "message": "Too many arguments for \"bar\"", "hint": null, "code": "call-arg", "severity": "error"}

[case testOutputJsonSyntaxError]
# flags: --output=json
klass foo
[out]
{"file": "main", "line": 2, "column": 7, "end_line": 2, "end_column": 8, "message": "Invalid syntax", "hint": null, "code": "syntax", "severity": "error"}
!!! Mypy crashed !!!
Comment thread
AA-Turner marked this conversation as resolved.
Loading