22from typing import FrozenSet
33from typing import Iterable
44from typing import NamedTuple
5+ from typing import Optional
56
67from typing_extensions import Final
78
8- UNUSED_IGNORE_MESSAGES : Final [FrozenSet [str ]] = frozenset (
9- {"error: unused 'type: ignore' comment" , 'error: unused "type: ignore" comment' }
10- )
9+ UNUSED_IGNORE_MESSAGES : Final [FrozenSet [str ]] = frozenset ({"error: unused 'type: ignore' comment" , 'error: unused "type: ignore" comment' })
1110
1211
1312class FilePosition (NamedTuple ):
@@ -18,20 +17,22 @@ class FilePosition(NamedTuple):
1817class MypyMessage (NamedTuple ):
1918 position : FilePosition
2019 message : str
20+ error_code : Optional [str ]
2121
2222
23- _mypy_output_re = re .compile (r"^([^:]+):(\d+):(.+) $" )
23+ _mypy_output_re = re .compile (r"^(?P<filename> [^:]+):(?P<line> \d+):(?P<message>.+?)(\[(?P<error_code>[a-z-]+)\])? $" )
2424
2525
26- def get_info_form_mypy_output (lines : Iterable [str ]) -> Iterable [MypyMessage ]:
26+ def get_info_from_mypy_output (lines : Iterable [str ]) -> Iterable [MypyMessage ]:
2727 for line in lines :
2828 line = line .strip ()
2929 match = _mypy_output_re .match (line )
3030 if match :
3131 yield MypyMessage (
3232 position = FilePosition (
33- filename = match .group (1 ).strip (),
34- line = int (match .group (2 )),
33+ filename = match .group ("filename" ).strip (),
34+ line = int (match .group ("line" )),
3535 ),
36- message = match .group (3 ).strip (),
36+ message = match .group ("message" ).strip (),
37+ error_code = match .group ("error_code" ),
3738 )
0 commit comments