5
5
"""
6
6
import re
7
7
8
+ supports_ignore_inline_noqa = False
9
+ supports_property_decorators = False
10
+ supports_ignore_self_only_init = False
8
11
try :
9
12
import pydocstyle as pep257
10
13
11
14
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 )
12
22
except ImportError :
13
23
import pep257
14
24
@@ -94,6 +104,33 @@ def add_options(cls, parser):
94
104
),
95
105
)
96
106
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
+
97
134
@classmethod
98
135
def parse_options (cls , options ):
99
136
"""Parse the configuration options given to flake8."""
@@ -103,21 +140,32 @@ def parse_options(cls, options):
103
140
if options .ignore_decorators
104
141
else None
105
142
)
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
106
147
107
148
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
120
157
)
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
+ )
121
169
122
170
def _check_source (self ):
123
171
try :
0 commit comments