Skip to content

Commit 2db7fd1

Browse files
committed
Add support for --property-decorators (pydocstyle 6.2.0) and --ignore-self-only-init (pydocstyle 6.3.0)
1 parent 76463dc commit 2db7fd1

File tree

1 file changed

+54
-12
lines changed

1 file changed

+54
-12
lines changed

flake8_docstrings.py

+54-12
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55
"""
66
import re
77

8+
supports_ignore_inline_noqa = False
9+
supports_property_decorators = False
10+
supports_ignore_self_only_init = False
811
try:
912
import pydocstyle as pep257
1013

1114
module_name = "pydocstyle"
15+
16+
pydocstyle_version = tuple(int(num) for num in pep257.__version__.split("."))
17+
supports_ignore_inline_noqa = pydocstyle_version > (5, 1, 1)
18+
supports_property_decorators = pydocstyle_version >= (6, 2, 0)
19+
supports_ignore_self_only_init = pydocstyle_version >= (6, 3, 0)
1220
except ImportError:
1321
import pep257
1422

@@ -94,6 +102,31 @@ def add_options(cls, parser):
94102
),
95103
)
96104

105+
if supports_property_decorators:
106+
from pydocstyle.config import ConfigurationParser
107+
108+
default_property_decorators = ConfigurationParser.DEFAULT_PROPERTY_DECORATORS
109+
parser.add_option(
110+
"--property-decorators",
111+
action="store",
112+
parse_from_config=True,
113+
default=default_property_decorators,
114+
help=(
115+
"consider any method decorated with one of these "
116+
"decorators as a property, and consequently allow "
117+
"a docstring which is not in imperative mood; default "
118+
f"is --property-decorators='{default_property_decorators}'"
119+
),
120+
)
121+
122+
if supports_ignore_self_only_init:
123+
parser.add_option(
124+
"--ignore-self-only-init",
125+
action="store_true",
126+
parse_from_config=True,
127+
help="ignore __init__ methods which only have a self param.",
128+
)
129+
97130
@classmethod
98131
def parse_options(cls, options):
99132
"""Parse the configuration options given to flake8."""
@@ -103,21 +136,30 @@ def parse_options(cls, options):
103136
if options.ignore_decorators
104137
else None
105138
)
139+
if supports_property_decorators:
140+
cls.property_decorators = options.property_decorators
141+
if supports_ignore_self_only_init:
142+
cls.ignore_self_only_init = options.ignore_self_only_init
106143

107144
def _call_check_source(self):
108-
try:
109-
return self.checker.check_source(
110-
self.source,
111-
self.filename,
112-
ignore_decorators=self.ignore_decorators,
113-
ignore_inline_noqa=True,
114-
)
115-
except TypeError: # for versions of pydocstyle 5.1.1 and below
116-
return self.checker.check_source(
117-
self.source,
118-
self.filename,
119-
ignore_decorators=self.ignore_decorators,
145+
check_source_kwargs = {}
146+
if supports_ignore_inline_noqa:
147+
check_source_kwargs["ignore_inline_noqa"] = True
148+
if supports_property_decorators:
149+
check_source_kwargs["property_decorators"] = (
150+
set(self.property_decorators.split(","))
151+
if self.property_decorators
152+
else None
120153
)
154+
if supports_ignore_self_only_init:
155+
check_source_kwargs["ignore_self_only_init"] = self.ignore_self_only_init
156+
157+
return self.checker.check_source(
158+
self.source,
159+
self.filename,
160+
ignore_decorators=self.ignore_decorators,
161+
**check_source_kwargs
162+
)
121163

122164
def _check_source(self):
123165
try:

0 commit comments

Comments
 (0)