From 2db7fd193e998663cffb0811c760d286ae2d4738 Mon Sep 17 00:00:00 2001 From: Niklas Mertsch Date: Thu, 19 Jan 2023 22:05:42 +0100 Subject: [PATCH 1/3] Add support for --property-decorators (pydocstyle 6.2.0) and --ignore-self-only-init (pydocstyle 6.3.0) --- flake8_docstrings.py | 66 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 12 deletions(-) diff --git a/flake8_docstrings.py b/flake8_docstrings.py index 700c5b7..b45a77f 100644 --- a/flake8_docstrings.py +++ b/flake8_docstrings.py @@ -5,10 +5,18 @@ """ import re +supports_ignore_inline_noqa = False +supports_property_decorators = False +supports_ignore_self_only_init = False try: import pydocstyle as pep257 module_name = "pydocstyle" + + pydocstyle_version = tuple(int(num) for num in pep257.__version__.split(".")) + supports_ignore_inline_noqa = pydocstyle_version > (5, 1, 1) + supports_property_decorators = pydocstyle_version >= (6, 2, 0) + supports_ignore_self_only_init = pydocstyle_version >= (6, 3, 0) except ImportError: import pep257 @@ -94,6 +102,31 @@ def add_options(cls, parser): ), ) + if supports_property_decorators: + from pydocstyle.config import ConfigurationParser + + default_property_decorators = ConfigurationParser.DEFAULT_PROPERTY_DECORATORS + parser.add_option( + "--property-decorators", + action="store", + parse_from_config=True, + default=default_property_decorators, + help=( + "consider any method decorated with one of these " + "decorators as a property, and consequently allow " + "a docstring which is not in imperative mood; default " + f"is --property-decorators='{default_property_decorators}'" + ), + ) + + if supports_ignore_self_only_init: + parser.add_option( + "--ignore-self-only-init", + action="store_true", + parse_from_config=True, + help="ignore __init__ methods which only have a self param.", + ) + @classmethod def parse_options(cls, options): """Parse the configuration options given to flake8.""" @@ -103,21 +136,30 @@ def parse_options(cls, options): if options.ignore_decorators else None ) + if supports_property_decorators: + cls.property_decorators = options.property_decorators + if supports_ignore_self_only_init: + cls.ignore_self_only_init = options.ignore_self_only_init def _call_check_source(self): - try: - return self.checker.check_source( - self.source, - self.filename, - ignore_decorators=self.ignore_decorators, - ignore_inline_noqa=True, - ) - except TypeError: # for versions of pydocstyle 5.1.1 and below - return self.checker.check_source( - self.source, - self.filename, - ignore_decorators=self.ignore_decorators, + check_source_kwargs = {} + if supports_ignore_inline_noqa: + check_source_kwargs["ignore_inline_noqa"] = True + if supports_property_decorators: + check_source_kwargs["property_decorators"] = ( + set(self.property_decorators.split(",")) + if self.property_decorators + else None ) + if supports_ignore_self_only_init: + check_source_kwargs["ignore_self_only_init"] = self.ignore_self_only_init + + return self.checker.check_source( + self.source, + self.filename, + ignore_decorators=self.ignore_decorators, + **check_source_kwargs + ) def _check_source(self): try: From 90edee904f250a1693c4a39231eb845f6e0ed783 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 19 Jan 2023 21:37:56 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- flake8_docstrings.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/flake8_docstrings.py b/flake8_docstrings.py index b45a77f..3bc0b1c 100644 --- a/flake8_docstrings.py +++ b/flake8_docstrings.py @@ -13,7 +13,9 @@ module_name = "pydocstyle" - pydocstyle_version = tuple(int(num) for num in pep257.__version__.split(".")) + pydocstyle_version = tuple( + int(num) for num in pep257.__version__.split(".") + ) supports_ignore_inline_noqa = pydocstyle_version > (5, 1, 1) supports_property_decorators = pydocstyle_version >= (6, 2, 0) supports_ignore_self_only_init = pydocstyle_version >= (6, 3, 0) @@ -105,7 +107,9 @@ def add_options(cls, parser): if supports_property_decorators: from pydocstyle.config import ConfigurationParser - default_property_decorators = ConfigurationParser.DEFAULT_PROPERTY_DECORATORS + default_property_decorators = ( + ConfigurationParser.DEFAULT_PROPERTY_DECORATORS + ) parser.add_option( "--property-decorators", action="store", @@ -152,13 +156,15 @@ def _call_check_source(self): else None ) if supports_ignore_self_only_init: - check_source_kwargs["ignore_self_only_init"] = self.ignore_self_only_init + check_source_kwargs[ + "ignore_self_only_init" + ] = self.ignore_self_only_init return self.checker.check_source( self.source, self.filename, ignore_decorators=self.ignore_decorators, - **check_source_kwargs + **check_source_kwargs, ) def _check_source(self): From 85c3467280d47fa22389eedcfe7b0580128f806a Mon Sep 17 00:00:00 2001 From: Niklas Mertsch Date: Fri, 20 Jan 2023 00:14:15 +0100 Subject: [PATCH 3/3] Improve consistency --- flake8_docstrings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake8_docstrings.py b/flake8_docstrings.py index 3bc0b1c..de7983a 100644 --- a/flake8_docstrings.py +++ b/flake8_docstrings.py @@ -16,7 +16,7 @@ pydocstyle_version = tuple( int(num) for num in pep257.__version__.split(".") ) - supports_ignore_inline_noqa = pydocstyle_version > (5, 1, 1) + supports_ignore_inline_noqa = pydocstyle_version >= (6, 0, 0) supports_property_decorators = pydocstyle_version >= (6, 2, 0) supports_ignore_self_only_init = pydocstyle_version >= (6, 3, 0) except ImportError: