-
-
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
- Loading branch information
Showing
13 changed files
with
261 additions
and
29 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,51 @@ | ||
# 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: | ||
with 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() |
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,33 @@ | ||
--- | ||
+++ | ||
@@ x,9 x,9 @@ | ||
|
||
|
||
async def nursery_no_cancel_point(): | ||
- with trio.CancelScope(): # error: 9, "trio", "CancelScope" | ||
- 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() | ||
@@ x,11 x,11 @@ | ||
|
||
async def nested_function_call(): | ||
|
||
- with trio.CancelScope(): # error: 9, "trio", "CancelScope" | ||
- async with trio.open_nursery() as n: | ||
+ # error: 9, "trio", "CancelScope" | ||
+ async with trio.open_nursery() as n: | ||
|
||
- def foo(): | ||
- n.start_soon(trio.sleep, 0) | ||
+ 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() | ||
+ # a false alarm in case we call foo()... but we can't check if they do | ||
+ foo() |
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(): | ||
with 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(): | ||
... | ||
|
||
|
||
async def nursery_with_start_soon(): | ||
with anyio.CancelScope(): | ||
async with anyio.create_task_group() as tg: | ||
tg.start_soon(bar) |
Oops, something went wrong.