Skip to content

Commit 9e77ce2

Browse files
committed
Fix bug causing false positives for PLU002
When an inner async function was immediately followed by a `return`, false positives could occur because other linters and formatters may require a specific number of blanks after classes and functions. One example is Black.
1 parent 84e3d36 commit 9e77ce2

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

flake8_plus/visitors/plu002_visitor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ def visit_Return(self, node: ast.Return) -> Any:
4949
Any: The result of calling `generic_visit`.
5050
"""
5151
# pylint: disable=invalid-name
52-
if not isinstance(self._previous_node, ast.FunctionDef | ast.ClassDef):
52+
if not isinstance(
53+
self._previous_node, ast.AsyncFunctionDef | ast.ClassDef | ast.FunctionDef
54+
):
5355
self._process_node(node)
5456
return self.generic_visit(node)
5557

tests/case_files/plu002/cases.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@
2525
}
2626
]
2727
},
28+
{
29+
"filename": "inner_coroutine.py",
30+
"cases": [
31+
{
32+
"expectation": { "blanks_expected": 0 },
33+
"problems": []
34+
},
35+
{
36+
"expectation": { "blanks_expected": 1 },
37+
"problems": [{ "line_number": 6, "col_offset": 8, "blanks_actual": 0 }]
38+
}
39+
]
40+
},
2841
{
2942
"filename": "inner_function.py",
3043
"cases": [
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from typing import Any, Callable, Coroutine
2+
3+
4+
def some_func() -> Callable[..., Coroutine[Any, Any, int]]:
5+
async def inner_func() -> int:
6+
return 27
7+
8+
return inner_func

0 commit comments

Comments
 (0)