Skip to content

Commit

Permalink
fix breakage from async generator
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Jul 15, 2021
1 parent 4eba9f3 commit d064832
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pyupgrade/_plugins/generator_expressions_pep289.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ def visit_Call(
isinstance(node.func, ast.Name) and
node.func.id in ALLOWED_FUNCS and
node.args and
isinstance(node.args[0], ast.ListComp)
isinstance(node.args[0], ast.ListComp) and
not any(
generator.is_async
for generator in node.args[0].generators
)
):
if len(node.args) == 1 and not node.keywords:
yield ast_to_offset(node.args[0]), _delete_list_comp_brackets
Expand Down
8 changes: 8 additions & 0 deletions tests/features/generator_expressions_pep289_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
'"".join([[i for _ in range(2)] for i in range(3)])\n',
id='string join (left alone for perf reasons)',
),
pytest.param(
'async def foo():\n'
' for i in range(3):\n'
' yield i\n'
'async def bar():\n'
' sum([i async for i in foo()])\n',
id='Contains async',
),
),
)
def test_fix_generator_expressions_noop(s):
Expand Down

0 comments on commit d064832

Please sign in to comment.