Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async generator breakage #491

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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