Skip to content

Commit e8c4f6c

Browse files
authored
Merge pull request #48 from NMertsch/main
Support options from pydocstyle 6.2.0 and 6.3.0
2 parents 76463dc + 85c3467 commit e8c4f6c

File tree

1 file changed

+60
-12
lines changed

1 file changed

+60
-12
lines changed

flake8_docstrings.py

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@
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(
17+
int(num) for num in pep257.__version__.split(".")
18+
)
19+
supports_ignore_inline_noqa = pydocstyle_version >= (6, 0, 0)
20+
supports_property_decorators = pydocstyle_version >= (6, 2, 0)
21+
supports_ignore_self_only_init = pydocstyle_version >= (6, 3, 0)
1222
except ImportError:
1323
import pep257
1424

@@ -94,6 +104,33 @@ def add_options(cls, parser):
94104
),
95105
)
96106

107+
if supports_property_decorators:
108+
from pydocstyle.config import ConfigurationParser
109+
110+
default_property_decorators = (
111+
ConfigurationParser.DEFAULT_PROPERTY_DECORATORS
112+
)
113+
parser.add_option(
114+
"--property-decorators",
115+
action="store",
116+
parse_from_config=True,
117+
default=default_property_decorators,
118+
help=(
119+
"consider any method decorated with one of these "
120+
"decorators as a property, and consequently allow "
121+
"a docstring which is not in imperative mood; default "
122+
f"is --property-decorators='{default_property_decorators}'"
123+
),
124+
)
125+
126+
if supports_ignore_self_only_init:
127+
parser.add_option(
128+
"--ignore-self-only-init",
129+
action="store_true",
130+
parse_from_config=True,
131+
help="ignore __init__ methods which only have a self param.",
132+
)
133+
97134
@classmethod
98135
def parse_options(cls, options):
99136
"""Parse the configuration options given to flake8."""
@@ -103,21 +140,32 @@ def parse_options(cls, options):
103140
if options.ignore_decorators
104141
else None
105142
)
143+
if supports_property_decorators:
144+
cls.property_decorators = options.property_decorators
145+
if supports_ignore_self_only_init:
146+
cls.ignore_self_only_init = options.ignore_self_only_init
106147

107148
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,
149+
check_source_kwargs = {}
150+
if supports_ignore_inline_noqa:
151+
check_source_kwargs["ignore_inline_noqa"] = True
152+
if supports_property_decorators:
153+
check_source_kwargs["property_decorators"] = (
154+
set(self.property_decorators.split(","))
155+
if self.property_decorators
156+
else None
120157
)
158+
if supports_ignore_self_only_init:
159+
check_source_kwargs[
160+
"ignore_self_only_init"
161+
] = self.ignore_self_only_init
162+
163+
return self.checker.check_source(
164+
self.source,
165+
self.filename,
166+
ignore_decorators=self.ignore_decorators,
167+
**check_source_kwargs,
168+
)
121169

122170
def _check_source(self):
123171
try:

0 commit comments

Comments
 (0)