11import re
2- from typing import FrozenSet
32from typing import Iterable
43from typing import NamedTuple
5-
4+ from typing import FrozenSet
5+ from typing import Optional
66from typing_extensions import Final
77
8- UNUSED_IGNORE_MESSAGES : Final [FrozenSet [str ]] = frozenset (
9- {"error: unused 'type: ignore' comment" , 'error: unused "type: ignore" comment' }
10- )
8+ UNUSED_IGNORE_MESSAGES : Final [FrozenSet [str ]] = frozenset ({"error: unused 'type: ignore' comment" , 'error: unused "type: ignore" comment' })
119
1210
1311class FilePosition (NamedTuple ):
@@ -18,20 +16,22 @@ class FilePosition(NamedTuple):
1816class MypyMessage (NamedTuple ):
1917 position : FilePosition
2018 message : str
19+ error_code : Optional [str ]
2120
2221
23- _mypy_output_re = re .compile (r"^([^:]+):(\d+):(.+) $" )
22+ _mypy_output_re = re .compile (r"^(?P<filename> [^:]+):(?P<line> \d+):(?P<message>.+?)(\[(?P<error_code>[a-z-]+)\])? $" )
2423
2524
26- def get_info_form_mypy_output (lines : Iterable [str ]) -> Iterable [MypyMessage ]:
25+ def get_info_from_mypy_output (lines : Iterable [str ]) -> Iterable [MypyMessage ]:
2726 for line in lines :
2827 line = line .strip ()
2928 match = _mypy_output_re .match (line )
3029 if match :
3130 yield MypyMessage (
3231 position = FilePosition (
33- filename = match .group (1 ).strip (),
34- line = int (match .group (2 )),
32+ filename = match .group ("filename" ).strip (),
33+ line = int (match .group ("line" )),
3534 ),
36- message = match .group (3 ).strip (),
35+ message = match .group ("message" ).strip (),
36+ error_code = match .group ("error_code" ),
3737 )
0 commit comments