From b5c70bdc5c47005fd7f729d97e9df5ec3da95016 Mon Sep 17 00:00:00 2001
From: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Date: Wed, 16 Feb 2022 15:03:49 +0100
Subject: [PATCH 1/5] Fix decorator parsing for async functions
---
docs/release_notes.rst | 2 ++
src/pydocstyle/parser.py | 1 +
src/tests/test_decorators.py | 15 +++++++++
src/tests/test_integration.py | 60 +++++++++++++++++++++++++++++++++++
4 files changed, 78 insertions(+)
diff --git a/docs/release_notes.rst b/docs/release_notes.rst
index a9060aef..23d59f64 100644
--- a/docs/release_notes.rst
+++ b/docs/release_notes.rst
@@ -18,6 +18,8 @@ New Features
Bug Fixes
* Fix ``--match`` option to only consider filename when matching full paths (#550).
+* Fix decorator parsing for async function. Resolves some false positives
+ with async functions and ``overload``. (#577)
6.1.1 - May 17th, 2021
---------------------------
diff --git a/src/pydocstyle/parser.py b/src/pydocstyle/parser.py
index 7165767a..cc768bbe 100644
--- a/src/pydocstyle/parser.py
+++ b/src/pydocstyle/parser.py
@@ -492,6 +492,7 @@ def parse_decorators(self):
self.current.value,
)
if self.current.kind == tk.NAME and self.current.value in [
+ 'async',
'def',
'class',
]:
diff --git a/src/tests/test_decorators.py b/src/tests/test_decorators.py
index cc5e3f06..6fd050b8 100644
--- a/src/tests/test_decorators.py
+++ b/src/tests/test_decorators.py
@@ -130,6 +130,21 @@ def some_method(self):
assert 'first_decorator' == decorators[0].name
assert '' == decorators[0].arguments
+ def test_parse_async_function_decorator(self):
+ """Decorators for async functions are also accumulated."""
+ code = textwrap.dedent("""\
+ @first_decorator
+ async def some_method(self):
+ pass
+ """)
+
+ module = checker.parse(io.StringIO(code), 'dummy.py')
+ decorators = module.children[0].decorators
+
+ assert 1 == len(decorators)
+ assert 'first_decorator' == decorators[0].name
+ assert '' == decorators[0].arguments
+
def test_parse_method_nested_decorator(self):
"""Method decorators are accumulated for nested methods."""
code = textwrap.dedent("""\
diff --git a/src/tests/test_integration.py b/src/tests/test_integration.py
index 9f255626..e383131b 100644
--- a/src/tests/test_integration.py
+++ b/src/tests/test_integration.py
@@ -621,6 +621,36 @@ def overloaded_func(a):
assert 'D103' not in out
+def test_overload_async_function(env):
+ """Async functions decorated with @overload trigger D418 error."""
+ with env.open('example.py', 'wt') as example:
+ example.write(textwrap.dedent('''\
+ from typing import overload
+
+
+ @overload
+ async def overloaded_func(a: int) -> str:
+ ...
+
+
+ @overload
+ async def overloaded_func(a: str) -> str:
+ """Foo bar documentation."""
+ ...
+
+
+ async def overloaded_func(a):
+ """Foo bar documentation."""
+ return str(a)
+
+ '''))
+ env.write_config(ignore="D100")
+ out, err, code = env.invoke()
+ assert code == 1
+ assert 'D418' in out
+ assert 'D103' not in out
+
+
def test_overload_method(env):
"""Methods decorated with @overload trigger D418 error."""
with env.open('example.py', 'wt') as example:
@@ -714,6 +744,36 @@ def overloaded_func(a):
assert code == 0
+def test_overload_async_function_valid(env):
+ """Valid case for overload decorated async functions.
+
+ This shouldn't throw any errors.
+ """
+ with env.open('example.py', 'wt') as example:
+ example.write(textwrap.dedent('''\
+ from typing import overload
+
+
+ @overload
+ async def overloaded_func(a: int) -> str:
+ ...
+
+
+ @overload
+ async def overloaded_func(a: str) -> str:
+ ...
+
+
+ def overloaded_func(a):
+ """Foo bar documentation."""
+ return str(a)
+
+ '''))
+ env.write_config(ignore="D100")
+ out, err, code = env.invoke()
+ assert code == 0
+
+
def test_overload_nested_function(env):
"""Nested functions decorated with @overload trigger D418 error."""
with env.open('example.py', 'wt') as example:
From a3f23686d52562aaea3521ac8159aeeb233b90d0 Mon Sep 17 00:00:00 2001
From: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Date: Tue, 3 Jan 2023 12:04:47 +0100
Subject: [PATCH 2/5] Move changelog entry
---
docs/release_notes.rst | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/release_notes.rst b/docs/release_notes.rst
index 8e6aeb64..cca6aded 100644
--- a/docs/release_notes.rst
+++ b/docs/release_notes.rst
@@ -11,6 +11,8 @@ Current Development Version
Bug Fixes
* Use tomllib/tomli to correctly read .toml files (#599, #600).
+* Fix decorator parsing for async function. Resolves some false positives
+ with async functions and ``overload``. (#577)
6.2.0 - January 2nd, 2023
---------------------------
@@ -25,8 +27,6 @@ New Features
Bug Fixes
* Fix ``--match`` option to only consider filename when matching full paths (#550).
-* Fix decorator parsing for async function. Resolves some false positives
- with async functions and ``overload``. (#577)
6.1.1 - May 17th, 2021
---------------------------
From c2c05d754874de7477c6a962952a1e27416fbada Mon Sep 17 00:00:00 2001
From: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Date: Tue, 3 Jan 2023 12:05:16 +0100
Subject: [PATCH 3/5] Fix error in test case
---
src/tests/test_integration.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/tests/test_integration.py b/src/tests/test_integration.py
index 81cf2fc9..2f2f57c6 100644
--- a/src/tests/test_integration.py
+++ b/src/tests/test_integration.py
@@ -764,7 +764,7 @@ async def overloaded_func(a: str) -> str:
...
- def overloaded_func(a):
+ async def overloaded_func(a):
"""Foo bar documentation."""
return str(a)
From dcac456a7f080ce39265ef1da7750f21f217da45 Mon Sep 17 00:00:00 2001
From: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Date: Tue, 3 Jan 2023 12:14:44 +0100
Subject: [PATCH 4/5] Move changelog entry again
---
docs/release_notes.rst | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/docs/release_notes.rst b/docs/release_notes.rst
index 7a1ca355..3e7eef71 100644
--- a/docs/release_notes.rst
+++ b/docs/release_notes.rst
@@ -5,15 +5,21 @@ Release Notes
`Semantic Versioning `_ specification.
-6.2.1 - January 3rd, 2023
+Current Development Version
---------------------------
Bug Fixes
-* Use tomllib/tomli to correctly read .toml files (#599, #600).
* Fix decorator parsing for async function. Resolves some false positives
with async functions and ``overload``. (#577)
+6.2.1 - January 3rd, 2023
+---------------------------
+
+Bug Fixes
+
+* Use tomllib/tomli to correctly read .toml files (#599, #600).
+
6.2.0 - January 2nd, 2023
---------------------------
From a0609611a9d93c4e05b530567e3872d1d1dec34c Mon Sep 17 00:00:00 2001
From: Sambhav Kothari
Date: Sun, 8 Jan 2023 17:52:12 +0000
Subject: [PATCH 5/5] Update release_notes.rst
---
docs/release_notes.rst | 2 ++
1 file changed, 2 insertions(+)
diff --git a/docs/release_notes.rst b/docs/release_notes.rst
index 1c82aa88..f0f6f691 100644
--- a/docs/release_notes.rst
+++ b/docs/release_notes.rst
@@ -7,6 +7,8 @@ Release Notes
6.2.3 - January 8th, 2023
---------------------------
+Bug Fixes
+
* Fix decorator parsing for async function. Resolves some false positives
with async functions and ``overload``. (#577)