errors.py 945 B

1234567891011121314151617181920212223242526272829
  1. from __future__ import annotations
  2. import mypy.errors
  3. from mypy.options import Options
  4. class Errors:
  5. def __init__(self, options: Options) -> None:
  6. self.num_errors = 0
  7. self.num_warnings = 0
  8. self._errors = mypy.errors.Errors(options, hide_error_codes=True)
  9. def error(self, msg: str, path: str, line: int) -> None:
  10. self._errors.report(line, None, msg, severity="error", file=path)
  11. self.num_errors += 1
  12. def note(self, msg: str, path: str, line: int) -> None:
  13. self._errors.report(line, None, msg, severity="note", file=path)
  14. def warning(self, msg: str, path: str, line: int) -> None:
  15. self._errors.report(line, None, msg, severity="warning", file=path)
  16. self.num_warnings += 1
  17. def new_messages(self) -> list[str]:
  18. return self._errors.new_messages()
  19. def flush_errors(self) -> None:
  20. for error in self.new_messages():
  21. print(error)