Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mypy_silent/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion mypy_silent/maho.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions mypy_silent/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -20,7 +22,9 @@ class MypyMessage(NamedTuple):
error_code: Optional[str]


_mypy_output_re = re.compile(r"^(?P<filename>[^:]+):(?P<line>\d+):(?P<message>.+?)(\[(?P<error_code>[a-z-]+)\])?$")
_mypy_output_re = re.compile(
r"^(?P<filename>[^:]+):(?P<line>\d+):(?P<message>.+?)(\[(?P<error_code>[a-z-]+)\])?$"
)


def get_info_from_mypy_output(lines: Iterable[str]) -> Iterable[MypyMessage]:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down