-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-code flake8-trio and flake8-async rules to match upstream (#10416)
Co-authored-by: Micha Reiser <[email protected]>
- Loading branch information
1 parent
2bfa34a
commit 3e33b0e
Showing
51 changed files
with
1,415 additions
and
588 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
30 changes: 17 additions & 13 deletions
30
crates/ruff_linter/resources/test/fixtures/flake8_async/ASYNC100.py
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,23 +1,27 @@ | ||
import urllib.request | ||
import requests | ||
import httpx | ||
import trio | ||
|
||
|
||
async def foo(): | ||
urllib.request.urlopen("http://example.com/foo/bar").read() | ||
async def func(): | ||
with trio.fail_after(): | ||
... | ||
|
||
|
||
async def foo(): | ||
requests.get() | ||
async def func(): | ||
with trio.fail_at(): | ||
await ... | ||
|
||
|
||
async def foo(): | ||
httpx.get() | ||
async def func(): | ||
with trio.move_on_after(): | ||
... | ||
|
||
|
||
async def foo(): | ||
requests.post() | ||
async def func(): | ||
with trio.move_at(): | ||
await ... | ||
|
||
|
||
async def foo(): | ||
httpx.post() | ||
async def func(): | ||
with trio.move_at(): | ||
async with trio.open_nursery() as nursery: | ||
... |
13 changes: 0 additions & 13 deletions
13
crates/ruff_linter/resources/test/fixtures/flake8_async/ASYNC102.py
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
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
69 changes: 69 additions & 0 deletions
69
crates/ruff_linter/resources/test/fixtures/flake8_async/ASYNC210.py
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,69 @@ | ||
import urllib | ||
import requests | ||
import httpx | ||
import urllib3 | ||
|
||
|
||
async def foo(): | ||
urllib.request.urlopen("http://example.com/foo/bar").read() # ASYNC210 | ||
|
||
|
||
async def foo(): | ||
requests.get() # ASYNC210 | ||
|
||
|
||
async def foo(): | ||
httpx.get() # ASYNC210 | ||
|
||
|
||
async def foo(): | ||
requests.post() # ASYNC210 | ||
|
||
|
||
async def foo(): | ||
httpx.post() # ASYNC210 | ||
|
||
|
||
async def foo(): | ||
requests.get() # ASYNC210 | ||
requests.get(...) # ASYNC210 | ||
requests.get # Ok | ||
print(requests.get()) # ASYNC210 | ||
print(requests.get(requests.get())) # ASYNC210 | ||
|
||
requests.options() # ASYNC210 | ||
requests.head() # ASYNC210 | ||
requests.post() # ASYNC210 | ||
requests.put() # ASYNC210 | ||
requests.patch() # ASYNC210 | ||
requests.delete() # ASYNC210 | ||
requests.foo() | ||
|
||
httpx.options("") # ASYNC210 | ||
httpx.head("") # ASYNC210 | ||
httpx.post("") # ASYNC210 | ||
httpx.put("") # ASYNC210 | ||
httpx.patch("") # ASYNC210 | ||
httpx.delete("") # ASYNC210 | ||
httpx.foo() # Ok | ||
|
||
urllib3.request() # ASYNC210 | ||
urllib3.request(...) # ASYNC210 | ||
|
||
urllib.request.urlopen("") # ASYNC210 | ||
|
||
r = {} | ||
r.get("not a sync http client") # Ok | ||
|
||
|
||
async def bar(): | ||
|
||
def request(): | ||
pass | ||
|
||
request() # Ok | ||
|
||
def urlopen(): | ||
pass | ||
|
||
urlopen() # Ok |
98 changes: 98 additions & 0 deletions
98
crates/ruff_linter/resources/test/fixtures/flake8_async/ASYNC22x.py
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,98 @@ | ||
import os | ||
import subprocess | ||
|
||
# Violation cases: | ||
|
||
|
||
async def func(): | ||
subprocess.run("foo") # ASYNC221 | ||
|
||
|
||
async def func(): | ||
subprocess.call("foo") # ASYNC221 | ||
|
||
|
||
async def func(): | ||
subprocess.foo(0) # OK | ||
|
||
|
||
async def func(): | ||
os.wait4(10) # ASYNC222 | ||
|
||
|
||
async def func(): | ||
os.wait(12) # ASYNC222 | ||
|
||
|
||
async def foo(): | ||
await async_fun( | ||
subprocess.getoutput() # ASYNC221 | ||
) | ||
subprocess.Popen() # ASYNC220 | ||
os.system() # ASYNC221 | ||
|
||
system() | ||
os.system.anything() | ||
os.anything() | ||
|
||
subprocess.run() # ASYNC221 | ||
subprocess.call() # ASYNC221 | ||
subprocess.check_call() # ASYNC221 | ||
subprocess.check_output() # ASYNC221 | ||
subprocess.getoutput() # ASYNC221 | ||
subprocess.getstatusoutput() # ASYNC221 | ||
|
||
await async_fun( | ||
subprocess.getoutput() # ASYNC221 | ||
) | ||
|
||
subprocess.anything() | ||
subprocess.foo() | ||
subprocess.bar.foo() | ||
subprocess() | ||
|
||
os.posix_spawn() # ASYNC221 | ||
os.posix_spawnp() # ASYNC221 | ||
|
||
os.spawn() | ||
os.spawn | ||
os.spawnllll() | ||
|
||
os.spawnl() # ASYNC221 | ||
os.spawnle() # ASYNC221 | ||
os.spawnlp() # ASYNC221 | ||
os.spawnlpe() # ASYNC221 | ||
os.spawnv() # ASYNC221 | ||
os.spawnve() # ASYNC221 | ||
os.spawnvp() # ASYNC221 | ||
os.spawnvpe() # ASYNC221 | ||
|
||
P_NOWAIT = os.P_NOWAIT | ||
|
||
# if mode is given, and is not os.P_WAIT: ASYNC220 | ||
os.spawnl(os.P_NOWAIT) # ASYNC220 | ||
os.spawnl(P_NOWAIT) # ASYNC220 | ||
os.spawnl(mode=os.P_NOWAIT) # ASYNC220 | ||
os.spawnl(mode=P_NOWAIT) # ASYNC220 | ||
|
||
P_WAIT = os.P_WAIT | ||
|
||
# if it is P_WAIT, ASYNC221 | ||
os.spawnl(P_WAIT) # ASYNC221 | ||
os.spawnl(mode=os.P_WAIT) # ASYNC221 | ||
os.spawnl(mode=P_WAIT) # ASYNC221 | ||
|
||
# other weird cases: ASYNC220 | ||
os.spawnl(0) # ASYNC220 | ||
os.spawnl(1) # ASYNC220 | ||
os.spawnl(foo()) # ASYNC220 | ||
|
||
# ASYNC222 | ||
os.wait() # ASYNC222 | ||
os.wait3() # ASYNC222 | ||
os.wait4() # ASYNC222 | ||
os.waitid() # ASYNC222 | ||
os.waitpid() # ASYNC222 | ||
|
||
os.waitpi() | ||
os.waiti() |
47 changes: 21 additions & 26 deletions
47
...es/test/fixtures/flake8_async/ASYNC101.py → ...es/test/fixtures/flake8_async/ASYNC230.py
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.