55A Flake8 plugin and pre-commit hook which checks to ensure modules have defined ``__all__``.
66"""
77#
8- # Copyright (c) 2020 Dominic Davis-Foster <dominic@davis-foster.co.uk>
8+ # Copyright (c) 2020-2022 Dominic Davis-Foster <dominic@davis-foster.co.uk>
99#
1010# Based on flake8_2020
1111# Copyright (c) 2019 Anthony Sottile
3939from domdf_python_tools .paths import PathPlus
4040from domdf_python_tools .typing import PathLike
4141from domdf_python_tools .utils import stderr_writer
42+ from flake8 .style_guide import find_noqa # type: ignore
4243
4344# this package
4445from flake8_dunder_all .utils import get_docstring_lineno , mark_text_ranges
@@ -226,8 +227,16 @@ def check_and_add_all(filename: PathLike, quote_type: str = '"') -> int:
226227 :param filename: The filename of the Python source file (``.py``) to check.
227228 :param quote_type: The type of quote to use for strings.
228229
229- :returns: ``0`` if the file already contains a ``__all__`` declaration or has no function or class definitions;
230- ``1`` otherwise. ``4`` indicates an error parsing the file.
230+ :returns:
231+
232+ * ``0`` if the file already contains a ``__all__`` declaration,
233+ has no function or class definitions, or has a `` # noqa: DALL000 ` comment.
234+ * ``1`` If ``__all__`` is absent.
235+ * ``4`` if an error was encountered when parsing the file.
236+
237+ .. versionchanged:: 0.2.0
238+
239+ Now returns ``0`` and doesn't add ``__all__`` if the file contains a `` # noqa: DALL000 ` comment.
231240 """
232241
233242 quotes = {"'" , '"' }
@@ -238,6 +247,11 @@ def check_and_add_all(filename: PathLike, quote_type: str = '"') -> int:
238247
239248 try :
240249 source = filename .read_text ()
250+ for line in source .splitlines ():
251+ noqas = find_noqa (line )
252+ if noqas is not None and "DALL000" in noqas .group (1 ).upper ().split (',' ):
253+ return 0
254+
241255 tree = ast .parse (source )
242256 if sys .version_info < (3 , 8 ): # pragma: no cover (<py38)
243257 mark_text_ranges (tree , source )
0 commit comments