Skip to content
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: 4 additions & 2 deletions flake8_trio/visitors/visitor91x.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,9 +769,11 @@ def visit_CompFor(self, node: cst.CompFor):

return False

# We don't have any logic on if generators are guaranteed to unroll, so always
# ignore their content by not visiting subnodes.
# The generator target will be immediately evaluated, but the other
# elements will be lazily evaluated as the generator is consumed so we don't
# visit them as any checkpoints in them are not guaranteed to execute.
def visit_GeneratorExp(self, node: cst.GeneratorExp):
node.for_in.iter.visit(self)
return False

def visit_Import(self, node: cst.Import):
Expand Down
16 changes: 16 additions & 0 deletions tests/autofix_files/trio910.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,3 +583,19 @@ async def foo_comprehension_2(): # error: 0, "exit", Statement("function defini

async def foo_comprehension_3():
[... async for x in bar()]


# Issue #714
# (await x async for y in await z)
# ^ ^ ^ this always runs!
# ^ ^ this might not run
# ^ this might not run


async def await_in_gen_target():
(print(x) for x in await foo())


async def await_everywhere_except_gen_target(): # error: 0, "exit", Statement("function definition", lineno)
(await x async for x in bar())
await trio.lowlevel.checkpoint()
5 changes: 5 additions & 0 deletions tests/autofix_files/trio910.py.diff
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,8 @@


async def foo_comprehension_3():
@@ x,3 x,4 @@

async def await_everywhere_except_gen_target(): # error: 0, "exit", Statement("function definition", lineno)
(await x async for x in bar())
+ await trio.lowlevel.checkpoint()
15 changes: 15 additions & 0 deletions tests/eval_files/trio910.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,3 +555,18 @@ async def foo_comprehension_2(): # error: 0, "exit", Statement("function defini

async def foo_comprehension_3():
[... async for x in bar()]


# Issue #714
# (await x async for y in await z)
# ^ ^ ^ this always runs!
# ^ ^ this might not run
# ^ this might not run


async def await_in_gen_target():
(print(x) for x in await foo())


async def await_everywhere_except_gen_target(): # error: 0, "exit", Statement("function definition", lineno)
(await x async for x in bar())