diff --git a/mypy_silent/cli.py b/mypy_silent/cli.py index 65f7cf4..06ba3c8 100644 --- a/mypy_silent/cli.py +++ b/mypy_silent/cli.py @@ -29,7 +29,9 @@ def mypy_silent( if info.message in UNUSED_IGNORE_MESSAGES: new_content = remove_type_ignore_comment(old_content) else: - new_content = add_type_ignore_comment(old_content, error_code=info.error_code) + new_content = add_type_ignore_comment( + old_content, error_code=info.error_code + ) file_contents[info.position.line - 1] = new_content with open(info.position.filename, "w") as f: f.writelines(file_contents) diff --git a/mypy_silent/maho.py b/mypy_silent/maho.py index 2be7229..145b93a 100644 --- a/mypy_silent/maho.py +++ b/mypy_silent/maho.py @@ -12,7 +12,11 @@ def add_type_ignore_comment(line: str, error_code: Optional[str]) -> str: if "# noqa" in line: return line.replace("# noqa", f"{type_ignore_comment} # noqa", 1) content_without_crlf = line.rstrip("\r\n") - return content_without_crlf + f" {type_ignore_comment}" + line[len(content_without_crlf) :] + return ( + content_without_crlf + + f" {type_ignore_comment}" + + line[len(content_without_crlf) :] + ) def remove_type_ignore_comment(line: str) -> str: diff --git a/mypy_silent/parser.py b/mypy_silent/parser.py index 695f827..ce203a8 100644 --- a/mypy_silent/parser.py +++ b/mypy_silent/parser.py @@ -6,7 +6,9 @@ from typing_extensions import Final -UNUSED_IGNORE_MESSAGES: Final[FrozenSet[str]] = frozenset({"error: unused 'type: ignore' comment", 'error: unused "type: ignore" comment'}) +UNUSED_IGNORE_MESSAGES: Final[FrozenSet[str]] = frozenset( + {"error: unused 'type: ignore' comment", 'error: unused "type: ignore" comment'} +) class FilePosition(NamedTuple): @@ -20,7 +22,9 @@ class MypyMessage(NamedTuple): error_code: Optional[str] -_mypy_output_re = re.compile(r"^(?P[^:]+):(?P\d+):(?P.+?)(\[(?P[a-z-]+)\])?$") +_mypy_output_re = re.compile( + r"^(?P[^:]+):(?P\d+):(?P.+?)(\[(?P[a-z-]+)\])?$" +) def get_info_from_mypy_output(lines: Iterable[str]) -> Iterable[MypyMessage]: diff --git a/pyproject.toml b/pyproject.toml index 3647de0..e193bfd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ typing-extensions = "^3.7.4;python<3.8" [tool.poetry.dev-dependencies] mypy = "^0.812" -pytest = "^6.2.4" +pytest = "^7.1.1" pytest-cov = "^2.12.1" [build-system]