diff --git a/numpydoc/tests/test_validate.py b/numpydoc/tests/test_validate.py index a0b30b9d..f3be498b 100644 --- a/numpydoc/tests/test_validate.py +++ b/numpydoc/tests/test_validate.py @@ -1862,6 +1862,9 @@ def test_cached_property(self): def test_three_decorators(self): """Test method with three decorators.""" + async def test_async(self): + """Test async method.""" + class TestValidatorClass: @pytest.mark.parametrize("invalid_name", ["unknown_mod", "unknown_mod.MyClass"]) @@ -1903,6 +1906,10 @@ def test_raises_for_invalid_attribute_name(self, invalid_name): "numpydoc.tests.test_validate.DecoratorClass.test_three_decorators", getsourcelines(DecoratorClass.test_three_decorators)[-1] + 3, ], + [ + "numpydoc.tests.test_validate.DecoratorClass.test_async", + getsourcelines(DecoratorClass.test_async)[-1], + ], ], ) def test_source_file_def_line_with_decorators(self, decorated_obj, def_line): diff --git a/numpydoc/validate.py b/numpydoc/validate.py index 30b0f413..235841ea 100644 --- a/numpydoc/validate.py +++ b/numpydoc/validate.py @@ -328,7 +328,8 @@ def source_file_def_line(self): def_line = next( i for i, x in enumerate( - re.match("^ *(def|class) ", s) for s in sourcelines[0] + re.match(r"^\s*(async\s+)?(?:def|class)\s+", s) + for s in sourcelines[0] ) if x is not None )