-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ASYNC100 now treats start_soon() as a cancel point (#327)
* ASYNC100 now treats start_soon() as a cancel point * oh derp, visitor91x is a CST visitor * start_soon now makes open_nursery a cancel point on exit
- Loading branch information
Showing
13 changed files
with
349 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# AUTOFIX | ||
# BASE_LIBRARY anyio | ||
# NOTRIO # trio.create_task_group doesn't exist | ||
# ASYNCIO_NO_ERROR | ||
import anyio | ||
|
||
|
||
async def bar() -> None: ... | ||
|
||
|
||
async def anyio_cancelscope(): | ||
# error: 9, "anyio", "CancelScope" | ||
... | ||
|
||
|
||
# see async100_trio for more comprehensive tests | ||
async def nursery_no_cancel_point(): | ||
# error: 9, "anyio", "CancelScope" | ||
async with anyio.create_task_group(): | ||
... | ||
|
||
|
||
async def nursery_with_start_soon(): | ||
with anyio.CancelScope(): | ||
async with anyio.create_task_group() as tg: | ||
tg.start_soon(bar) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
+++ | ||
@@ x,15 x,15 @@ | ||
|
||
|
||
async def anyio_cancelscope(): | ||
- with anyio.CancelScope(): # error: 9, "anyio", "CancelScope" | ||
- ... | ||
+ # error: 9, "anyio", "CancelScope" | ||
+ ... | ||
|
||
|
||
# see async100_trio for more comprehensive tests | ||
async def nursery_no_cancel_point(): | ||
- with anyio.CancelScope(): # error: 9, "anyio", "CancelScope" | ||
- async with anyio.create_task_group(): | ||
- ... | ||
+ # error: 9, "anyio", "CancelScope" | ||
+ async with anyio.create_task_group(): | ||
+ ... | ||
|
||
|
||
async def nursery_with_start_soon(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,75 @@ | ||
# AUTOFIX | ||
# ASYNCIO_NO_ERROR # asyncio.open_nursery doesn't exist | ||
# ANYIO_NO_ERROR # anyio.open_nursery doesn't exist | ||
# NOANYIO # anyio.open_nursery doesn't exist | ||
import trio | ||
|
||
|
||
async def nursery_no_cancel_point(): | ||
with trio.CancelScope(): # should error, but reverted PR | ||
async with trio.open_nursery(): | ||
... | ||
# error: 9, "trio", "CancelScope" | ||
async with trio.open_nursery(): | ||
... | ||
|
||
|
||
# but it is a cancel point if the nursery contains a call to start_soon() | ||
|
||
|
||
async def nursery_start_soon(): | ||
with trio.CancelScope(): | ||
async with trio.open_nursery() as n: | ||
n.start_soon(trio.sleep, 0) | ||
|
||
|
||
async def nursery_start_soon_misnested(): | ||
async with trio.open_nursery() as n: | ||
# error: 13, "trio", "CancelScope" | ||
n.start_soon(trio.sleep, 0) | ||
|
||
|
||
async def nested_scope(): | ||
with trio.CancelScope(): | ||
with trio.CancelScope(): | ||
async with trio.open_nursery() as n: | ||
n.start_soon(trio.sleep, 0) | ||
|
||
|
||
async def nested_nursery(): | ||
with trio.CancelScope(): | ||
async with trio.open_nursery() as n: | ||
async with trio.open_nursery() as n2: | ||
n2.start_soon(trio.sleep, 0) | ||
|
||
|
||
async def nested_function_call(): | ||
|
||
# error: 9, "trio", "CancelScope" | ||
async with trio.open_nursery() as n: | ||
|
||
def foo(): | ||
n.start_soon(trio.sleep, 0) | ||
|
||
# a false alarm in case we call foo()... but we can't check if they do | ||
foo() | ||
|
||
|
||
# insert cancel point on nursery exit, not at the start_soon call | ||
async def cancel_point_on_nursery_exit(): | ||
with trio.CancelScope(): | ||
async with trio.open_nursery() as n: | ||
# error: 17, "trio", "CancelScope" | ||
n.start_soon(trio.sleep, 0) | ||
|
||
|
||
# async100 does not consider *redundant* cancel scopes | ||
async def redundant_cancel_scope(): | ||
with trio.CancelScope(): | ||
with trio.CancelScope(): | ||
await trio.lowlevel.checkpoint() | ||
|
||
|
||
# but if it did then none of these scopes should be marked redundant | ||
# The inner checks task startup, the outer checks task exit | ||
async def nursery_exit_blocks_with_start(): | ||
with trio.CancelScope(): | ||
async with trio.open_nursery() as n: | ||
with trio.CancelScope(): | ||
await n.start(trio.sleep, 0) |
Oops, something went wrong.