-
-
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.
Implement basic autofix infrastructure and autofixer for TRIO100
- Loading branch information
Showing
13 changed files
with
320 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# type: ignore | ||
|
||
import trio | ||
|
||
# error: 5, "trio", "move_on_after" | ||
... | ||
|
||
|
||
async def function_name(): | ||
# fmt: off | ||
...; ...; ... | ||
# fmt: on | ||
# error: 15, "trio", "fail_after" | ||
... | ||
# error: 15, "trio", "fail_at" | ||
... | ||
# error: 15, "trio", "move_on_after" | ||
... | ||
# error: 15, "trio", "move_on_at" | ||
... | ||
# error: 15, "trio", "CancelScope" | ||
... | ||
|
||
with trio.move_on_after(10): | ||
await trio.sleep(1) | ||
|
||
with trio.move_on_after(10): | ||
await trio.sleep(1) | ||
print("hello") | ||
|
||
with trio.move_on_after(10): | ||
while True: | ||
await trio.sleep(1) | ||
print("hello") | ||
|
||
with open("filename") as _: | ||
... | ||
|
||
# error: 9, "trio", "fail_after" | ||
... | ||
|
||
send_channel, receive_channel = trio.open_memory_channel(0) | ||
async with trio.fail_after(10): | ||
async with send_channel: | ||
... | ||
|
||
async with trio.fail_after(10): | ||
async for _ in receive_channel: | ||
... | ||
|
||
# error: 15, "trio", "fail_after" | ||
for _ in receive_channel: | ||
... | ||
|
||
# fix missed alarm when function is defined inside the with scope | ||
# error: 9, "trio", "move_on_after" | ||
|
||
async def foo(): | ||
await trio.sleep(1) | ||
|
||
# error: 9, "trio", "move_on_after" | ||
if ...: | ||
|
||
async def foo(): | ||
if ...: | ||
await trio.sleep(1) | ||
|
||
async with random_ignored_library.fail_after(10): | ||
... | ||
|
||
|
||
async def function_name2(): | ||
with ( | ||
open("") as _, | ||
trio.fail_after(10), # error: 8, "trio", "fail_after" | ||
): | ||
... | ||
|
||
with ( | ||
trio.fail_after(5), # error: 8, "trio", "fail_after" | ||
open("") as _, | ||
trio.move_on_after(5), # error: 8, "trio", "move_on_after" | ||
): | ||
... |
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,43 @@ | ||
import trio | ||
|
||
# a | ||
# b | ||
# error: 5, "trio", "move_on_after" | ||
# c | ||
# d | ||
print(1) # e | ||
# f | ||
# g | ||
print(2) # h | ||
# i | ||
# j | ||
print(3) # k | ||
# l | ||
# m | ||
pass | ||
# n | ||
|
||
# error: 5, "trio", "move_on_after" | ||
... | ||
|
||
|
||
# a | ||
# b | ||
# fmt: off | ||
...;...;... | ||
# fmt: on | ||
# c | ||
# d | ||
|
||
# Doesn't autofix With's with multiple withitems | ||
with ( | ||
trio.move_on_after(10), # error: 4, "trio", "move_on_after" | ||
open("") as f, | ||
): | ||
... | ||
|
||
|
||
# extreme case I'm not gonna care about, i.e. one item in the with, but it's multiline. | ||
# Only these leading comments, and the last one, are kept, the rest are lost. | ||
# this comment is kept | ||
... |
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
Oops, something went wrong.