Skip to content

Commit e0df1ae

Browse files
committed
Add support for async functions.
1 parent 52ecbdb commit e0df1ae

File tree

5 files changed

+114
-5
lines changed

5 files changed

+114
-5
lines changed

flake8_params/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,13 @@ class Visitor(flake8_helper.Visitor):
137137
AST node visitor for identifying mismatches between function signatures and docstring params.
138138
"""
139139

140-
# TODO: async functions
141-
142140
def visit_FunctionDef(self, node: ast.FunctionDef) -> None: # noqa: D102
141+
self._visit_function(node)
142+
143+
def visit_AsyncFunctionDef(self, node: ast.AsyncFunctionDef) -> None: # noqa: D102
144+
self._visit_function(node)
145+
146+
def _visit_function(self, node: Union[ast.FunctionDef, ast.AsyncFunctionDef]) -> None:
143147
if node.name == "__init__":
144148
self.generic_visit(node)
145149
return
@@ -198,7 +202,8 @@ def visit_ClassDef(self, node: ast.ClassDef) -> None: # noqa: D102
198202
else:
199203
# No __init__; maybe it comes from a base class.
200204
# TODO: check for base classes and still error if non exist
201-
return None
205+
self.generic_visit(node)
206+
return
202207

203208
error = check_params(signature_args, docstring_args, decorators)
204209
if not error:

repo_helper.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ license: 'MIT'
1212
short_desc: "A flake8 plugin which checks for mismatches between function signatures and docstring params."
1313

1414
use_whey: true
15-
min_coverage: 97
15+
min_coverage: 100
1616
sphinx_html_theme: furo
1717
docs_fail_on_warning: true
1818
enable_conda: false

tests/example_code.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,100 @@ def a_command(foo):
190190

191191
def no_docstring(foo, bar, baz):
192192
pass
193+
194+
195+
async def missing_in_docstring_async(foo, bar, baz):
196+
"""
197+
Does something.
198+
199+
:param foo:
200+
:param bar:
201+
"""
202+
203+
204+
async def has_self_async(self, foo, bar, baz):
205+
"""
206+
Does something.
207+
208+
:param foo:
209+
:param bar:
210+
:param baz:
211+
"""
212+
213+
214+
async def missing_in_docstring_with_self_async(self, foo, bar, baz):
215+
"""
216+
Does something.
217+
218+
:param bar:
219+
:param baz:
220+
"""
221+
222+
223+
async def docstring_wrong_order_async(self, foo, bar, baz):
224+
"""
225+
Does something.
226+
227+
:param bar:
228+
:param foo:
229+
:param baz:
230+
"""
231+
232+
233+
async def missing_in_signature_async(foo, bar):
234+
"""
235+
Does something.
236+
237+
:param foo:
238+
:param bar:
239+
:param baz:
240+
"""
241+
242+
243+
async def missing_in_signature_with_self_async(self, foo, bar):
244+
"""
245+
Does something.
246+
247+
:param foo:
248+
:param bar:
249+
:param baz:
250+
"""
251+
252+
253+
class AsyncClass:
254+
"""
255+
A class.
256+
"""
257+
258+
@classmethod
259+
async def is_classmethod(cls, foo, bar, baz):
260+
"""
261+
Does something.
262+
263+
:param foo:
264+
:param bar:
265+
:param baz:
266+
"""
267+
268+
@classmethod
269+
async def missing_in_docstring_with_classmethod(cls, foo, bar, baz):
270+
"""
271+
Does something.
272+
273+
:param foo:
274+
:param baz:
275+
"""
276+
277+
@classmethod
278+
async def missing_in_signature_with_classmethod(cls, foo, baz):
279+
"""
280+
Does something.
281+
282+
:param foo:
283+
:param bar:
284+
:param baz:
285+
"""
286+
287+
288+
async def no_docstring_async(foo, bar, baz):
289+
pass

tests/test_flake8_params_/test_plugin.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@
88
90:1: PRM003 Extra parameters in docstring.
99
112:0: PRM003 Extra parameters in docstring.
1010
125:0: PRM001 Docstring parameters in wrong order.
11+
195:0: PRM002 Missing parameters in docstring.
12+
214:0: PRM002 Missing parameters in docstring.
13+
223:0: PRM001 Docstring parameters in wrong order.
14+
233:0: PRM003 Extra parameters in docstring.
15+
243:0: PRM003 Extra parameters in docstring.
16+
269:1: PRM002 Missing parameters in docstring.
17+
278:1: PRM003 Extra parameters in docstring.

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ unused-arguments-ignore-variadic-names = True
195195
plugins = coverage_pyver_pragma
196196
197197
[coverage:report]
198-
fail_under = 97
198+
fail_under = 100
199199
show_missing = True
200200
exclude_lines =
201201
raise AssertionError

0 commit comments

Comments
 (0)