Closed simon-liebehenschel closed 2 years ago
Thank you for the example, @AIGeneratedUsername :
async def g2():
async for v in g1():
yield v
The AST looks like this:
AsyncFunctionDef(
name='g2',
args=arguments(posonlyargs=[], args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]),
body=[
AsyncFor(
target=Name(id='v', ctx=Store()),
iter=Call(
func=Name(id='g1', ctx=Load()),
args=[],
keywords=[],
),
body=[
Expr(
value=Yield(
value=Name(id='v', ctx=Load()),
),
),
],
orelse=[],
type_comment=None,
),
],
decorator_list=[],
returns=None,
type_comment=None,
),
Desired change
Explanation
Python does not support 'yield from' inside async functions
https://www.python.org/dev/peps/pep-0525/#asynchronous-yield-from
If 'flake8-simplify' already can check if a function is "async" or not, then the issue has to be easy to fix.
Example
This is an example where the mentioned rule(s) would currently be suboptimal:
Copied from the https://www.python.org/dev/peps/pep-0525/#asynchronous-yield-from: