Files
FusionAGI/.venv/lib/python3.12/site-packages/mypy/error_formatter.py
defiQUG c052b07662
Some checks failed
Tests / test (3.10) (push) Has been cancelled
Tests / test (3.11) (push) Has been cancelled
Tests / test (3.12) (push) Has been cancelled
Tests / lint (push) Has been cancelled
Tests / docker (push) Has been cancelled
Initial commit: add .gitignore and README
2026-02-09 21:51:42 -08:00

38 lines
1.1 KiB
Python

"""Defines the different custom formats in which mypy can output."""
import json
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from mypy.errors import MypyError
class ErrorFormatter(ABC):
"""Base class to define how errors are formatted before being printed."""
@abstractmethod
def report_error(self, error: "MypyError") -> str:
raise NotImplementedError
class JSONFormatter(ErrorFormatter):
"""Formatter for basic JSON output format."""
def report_error(self, error: "MypyError") -> str:
"""Prints out the errors as simple, static JSON lines."""
return json.dumps(
{
"file": error.file_path,
"line": error.line,
"column": error.column,
"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,
"severity": error.severity,
}
)
OUTPUT_CHOICES = {"json": JSONFormatter()}