Skip to content

Commit

Permalink
Fix bug causing false positives for PLU002
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sorenlind committed Nov 28, 2022
1 parent 84e3d36 commit 9e77ce2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion flake8_plus/visitors/plu002_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def visit_Return(self, node: ast.Return) -> Any:
Any: The result of calling `generic_visit`.
"""
# pylint: disable=invalid-name
if not isinstance(self._previous_node, ast.FunctionDef | ast.ClassDef):
if not isinstance(
self._previous_node, ast.AsyncFunctionDef | ast.ClassDef | ast.FunctionDef
):
self._process_node(node)
return self.generic_visit(node)

Expand Down
13 changes: 13 additions & 0 deletions tests/case_files/plu002/cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@
}
]
},
{
"filename": "inner_coroutine.py",
"cases": [
{
"expectation": { "blanks_expected": 0 },
"problems": []
},
{
"expectation": { "blanks_expected": 1 },
"problems": [{ "line_number": 6, "col_offset": 8, "blanks_actual": 0 }]
}
]
},
{
"filename": "inner_function.py",
"cases": [
Expand Down
8 changes: 8 additions & 0 deletions tests/case_files/plu002/inner_coroutine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from typing import Any, Callable, Coroutine


def some_func() -> Callable[..., Coroutine[Any, Any, int]]:
async def inner_func() -> int:
return 27

return inner_func

0 comments on commit 9e77ce2

Please sign in to comment.