Skip to content

Commit 6101eb3

Browse files
LinyanZhangzhanglinyan
andauthored
fix: resolve numpydoc StopIteration error for async functions (#675)
* fix: resolve numpydoc StopIteration error for async functions * TST: add test for source_file_def_line with async functions --------- Co-authored-by: zhanglinyan <zhanglinyan@lixiang.com>
1 parent 2dc14cf commit 6101eb3

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

numpydoc/tests/test_validate.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,9 @@ def test_cached_property(self):
18621862
def test_three_decorators(self):
18631863
"""Test method with three decorators."""
18641864

1865+
async def test_async(self):
1866+
"""Test async method."""
1867+
18651868

18661869
class TestValidatorClass:
18671870
@pytest.mark.parametrize("invalid_name", ["unknown_mod", "unknown_mod.MyClass"])
@@ -1903,6 +1906,10 @@ def test_raises_for_invalid_attribute_name(self, invalid_name):
19031906
"numpydoc.tests.test_validate.DecoratorClass.test_three_decorators",
19041907
getsourcelines(DecoratorClass.test_three_decorators)[-1] + 3,
19051908
],
1909+
[
1910+
"numpydoc.tests.test_validate.DecoratorClass.test_async",
1911+
getsourcelines(DecoratorClass.test_async)[-1],
1912+
],
19061913
],
19071914
)
19081915
def test_source_file_def_line_with_decorators(self, decorated_obj, def_line):

numpydoc/validate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ def source_file_def_line(self):
328328
def_line = next(
329329
i
330330
for i, x in enumerate(
331-
re.match("^ *(def|class) ", s) for s in sourcelines[0]
331+
re.match(r"^\s*(async\s+)?(?:def|class)\s+", s)
332+
for s in sourcelines[0]
332333
)
333334
if x is not None
334335
)

0 commit comments

Comments
 (0)