import typing
import re


def _get_mypy_errors(stdout) -> typing.Dict[int, typing.Dict[str, str]]:
    """Parse line number and error message."""
    errors: typing.Dict[int, typing.Dict[str, typing.Any]] = {}
    # last line is summary of errors
    for error in [x for x in stdout.split("\n") if x != ""][:-1]:
        matches = re.match(
            r".+\.py:(?P<lineno>\d+): error: (?P<msg>.+)  \[(?P<errcode>.+)\]",
            error,
        )
        if matches is not None:
            match_dict = matches.groupdict()
            errors[int(match_dict["lineno"])] = {
                "msg": match_dict["msg"],
                "errcode": match_dict["errcode"],
            }
    return errors