diff --git a/mypy/error_formatter.py b/mypy/error_formatter.py index a9a95978f94a..ffc6b6747596 100644 --- a/mypy/error_formatter.py +++ b/mypy/error_formatter.py @@ -29,7 +29,7 @@ def report_error(self, error: "MypyError") -> str: "message": error.message, "hint": None if len(error.hints) == 0 else "\n".join(error.hints), "code": None if error.errorcode is None else error.errorcode.code, - "is_note": error.is_note, + "severity": error.severity, } ) diff --git a/mypy/errors.py b/mypy/errors.py index 9f1665fedc31..7a937da39c20 100644 --- a/mypy/errors.py +++ b/mypy/errors.py @@ -1296,14 +1296,14 @@ def __init__( column: int, message: str, errorcode: ErrorCode | None, - is_note: bool = False, + severity: Literal["error", "note"], ) -> None: self.file_path = file_path self.line = line self.column = column self.message = message self.errorcode = errorcode - self.is_note = is_note + self.severity = severity self.hints: list[str] = [] @@ -1326,14 +1326,14 @@ def create_errors(error_tuples: list[ErrorTuple]) -> list[MypyError]: error = latest_error_at_location.get(error_location) if error is None: # This is purely a note, with no error correlated to it - error = MypyError(file_path, line, column, message, errorcode, is_note=True) + error = MypyError(file_path, line, column, message, errorcode, severity="note") errors.append(error) continue error.hints.append(message) else: - error = MypyError(file_path, line, column, message, errorcode) + error = MypyError(file_path, line, column, message, errorcode, severity="error") errors.append(error) error_location = (file_path, line, column) latest_error_at_location[error_location] = error diff --git a/test-data/unit/outputjson.test b/test-data/unit/outputjson.test index 72d36a50415d..43649b7b781d 100644 --- a/test-data/unit/outputjson.test +++ b/test-data/unit/outputjson.test @@ -18,7 +18,7 @@ def foo() -> None: foo(1) [out] -{"file": "main", "line": 5, "column": 0, "message": "Too many arguments for \"foo\"", "hint": null, "code": "call-arg", "is_note": false} +{"file": "main", "line": 5, "column": 0, "message": "Too many arguments for \"foo\"", "hint": null, "code": "call-arg", "severity": "error"} [case testOutputJsonWithHint] # flags: --output=json @@ -39,6 +39,6 @@ foo('42') def bar() -> None: ... bar('42') [out] -{"file": "main", "line": 12, "column": 12, "message": "Revealed type is \"Overload(def (), def (x: builtins.int))\"", "hint": null, "code": "misc", "is_note": true} -{"file": "main", "line": 14, "column": 0, "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", "is_note": false} -{"file": "main", "line": 17, "column": 0, "message": "Too many arguments for \"bar\"", "hint": null, "code": "call-arg", "is_note": false} +{"file": "main", "line": 12, "column": 12, "message": "Revealed type is \"Overload(def (), def (x: builtins.int))\"", "hint": null, "code": "misc", "severity": "note"} +{"file": "main", "line": 14, "column": 0, "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, "message": "Too many arguments for \"bar\"", "hint": null, "code": "call-arg", "severity": "error"}