From 30976acb5519994266ee59e464162ac36c5bd0da Mon Sep 17 00:00:00 2001 From: "S. Co1" Date: Mon, 13 May 2024 16:03:29 -0400 Subject: [PATCH] Add test for linting empty source --- flake8_annotations/checker.py | 6 ++++-- testing/test_empty_src.py | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 testing/test_empty_src.py diff --git a/flake8_annotations/checker.py b/flake8_annotations/checker.py index 7072933..9dbcb88 100644 --- a/flake8_annotations/checker.py +++ b/flake8_annotations/checker.py @@ -43,7 +43,7 @@ def __init__(self, tree: t.Optional[ast.Module], lines: t.List[str]): # Type ignores are provided by ast at the module level & we'll need them later when deciding # whether or not to emit errors for a given function self._type_ignore_lineno = {ti.lineno for ti in self.tree.type_ignores} - self._has_mypy_ignore_errors = "# mypy: ignore-errors" in lines[0] + self._has_mypy_ignore_errors = "# mypy: ignore-errors" in lines[0] if lines else False # Set by flake8's config parser self.suppress_none_returning: bool @@ -119,7 +119,9 @@ def run(self) -> t.Generator[FORMATTED_ERROR, None, None]: if function.lineno in self._type_ignore_lineno: # function-level ignore continue - elif (1 in self._type_ignore_lineno) or (self._has_mypy_ignore_errors): + elif (1 in self._type_ignore_lineno) or ( + self._has_mypy_ignore_errors + ): # pragma: no branch # module-level ignore # lineno from ast is 1-indexed continue diff --git a/testing/test_empty_src.py b/testing/test_empty_src.py new file mode 100644 index 0000000..a191a3a --- /dev/null +++ b/testing/test_empty_src.py @@ -0,0 +1,6 @@ +from testing.helpers import check_source + + +def test_empty_source() -> None: + errs = check_source("") + assert len(list(errs)) == 0