File: errors.py

package info (click to toggle)
mypy 1.15.0-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 20,576 kB
  • sloc: python: 105,159; cpp: 11,380; ansic: 6,629; makefile: 247; sh: 20
file content (29 lines) | stat: -rw-r--r-- 945 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from __future__ import annotations

import mypy.errors
from mypy.options import Options


class Errors:
    def __init__(self, options: Options) -> None:
        self.num_errors = 0
        self.num_warnings = 0
        self._errors = mypy.errors.Errors(options, hide_error_codes=True)

    def error(self, msg: str, path: str, line: int) -> None:
        self._errors.report(line, None, msg, severity="error", file=path)
        self.num_errors += 1

    def note(self, msg: str, path: str, line: int) -> None:
        self._errors.report(line, None, msg, severity="note", file=path)

    def warning(self, msg: str, path: str, line: int) -> None:
        self._errors.report(line, None, msg, severity="warning", file=path)
        self.num_warnings += 1

    def new_messages(self) -> list[str]:
        return self._errors.new_messages()

    def flush_errors(self) -> None:
        for error in self.new_messages():
            print(error)