diff --git a/test_files/dont_touch_e501.expected.py b/test_files/dont_touch_e501.expected.py new file mode 100644 index 0000000..4a1320e --- /dev/null +++ b/test_files/dont_touch_e501.expected.py @@ -0,0 +1,5 @@ +if compat.py314: + + from annotationlib import call_annotate_function # type: ignore[import-not-found,unused-ignore] # noqa: E501 + from annotationlib import Format + diff --git a/test_files/dont_touch_e501.py b/test_files/dont_touch_e501.py new file mode 100644 index 0000000..4a1320e --- /dev/null +++ b/test_files/dont_touch_e501.py @@ -0,0 +1,5 @@ +if compat.py314: + + from annotationlib import call_annotate_function # type: ignore[import-not-found,unused-ignore] # noqa: E501 + from annotationlib import Format + diff --git a/tests.py b/tests.py index c5ba3c5..1981811 100644 --- a/tests.py +++ b/tests.py @@ -110,6 +110,9 @@ def test_empty_file(self): def test_conditional_imports(self): self._assert_file("conditional_imports.py") + def test_dont_touch_e501(self): + self._assert_file("dont_touch_e501.py", opts=["--black-line-length", "79"],) + def test_sqla_test_file(self): self._assert_file("sqla_test_file.py") diff --git a/zimports/zimports.py b/zimports/zimports.py index a60516b..954d49c 100644 --- a/zimports/zimports.py +++ b/zimports/zimports.py @@ -800,7 +800,7 @@ def _lines_with_newlines(lines) -> Iterator[str]: def _mini_black_format(lines: list[str], line_length) -> Iterator[str]: for line in lines: - if len(line) >= line_length: + if len(line) >= line_length and not re.search(r"noqa.*E501", line): from_imp_match = re.match(r"^(\s*)from (.+?) import (.+)", line) if not from_imp_match: yield line