Skip to content

Commit

Permalink
Merge branch 'main' into charlie/quote
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Dec 13, 2023
2 parents 5027f0d + 4d2ee5b commit f3eaec7
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 194 deletions.
13 changes: 11 additions & 2 deletions crates/ruff_linter/resources/test/fixtures/flake8_trio/TRIO115.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ async def func():
trio.sleep(e) # TRIO115

m_x, m_y = 0
trio.sleep(m_y) # TRIO115
trio.sleep(m_x) # TRIO115
trio.sleep(m_y) # OK
trio.sleep(m_x) # OK

m_a = m_b = 0
trio.sleep(m_a) # TRIO115
Expand All @@ -43,6 +43,8 @@ async def func():


def func():
import trio

trio.run(trio.sleep(0)) # TRIO115


Expand All @@ -55,3 +57,10 @@ def func():

async def func():
await sleep(seconds=0) # TRIO115


def func():
import trio

if (walrus := 0) == 0:
trio.sleep(walrus) # TRIO115
Original file line number Diff line number Diff line change
Expand Up @@ -143,47 +143,7 @@ TRIO115.py:29:5: TRIO115 [*] Use `trio.lowlevel.checkpoint()` instead of `trio.s
29 |+ trio.lowlevel.checkpoint() # TRIO115
30 30 |
31 31 | m_x, m_y = 0
32 32 | trio.sleep(m_y) # TRIO115

TRIO115.py:32:5: TRIO115 [*] Use `trio.lowlevel.checkpoint()` instead of `trio.sleep(0)`
|
31 | m_x, m_y = 0
32 | trio.sleep(m_y) # TRIO115
| ^^^^^^^^^^^^^^^ TRIO115
33 | trio.sleep(m_x) # TRIO115
|
= help: Replace with `trio.lowlevel.checkpoint()`

Safe fix
29 29 | trio.sleep(e) # TRIO115
30 30 |
31 31 | m_x, m_y = 0
32 |- trio.sleep(m_y) # TRIO115
32 |+ trio.lowlevel.checkpoint() # TRIO115
33 33 | trio.sleep(m_x) # TRIO115
34 34 |
35 35 | m_a = m_b = 0

TRIO115.py:33:5: TRIO115 [*] Use `trio.lowlevel.checkpoint()` instead of `trio.sleep(0)`
|
31 | m_x, m_y = 0
32 | trio.sleep(m_y) # TRIO115
33 | trio.sleep(m_x) # TRIO115
| ^^^^^^^^^^^^^^^ TRIO115
34 |
35 | m_a = m_b = 0
|
= help: Replace with `trio.lowlevel.checkpoint()`

Safe fix
30 30 |
31 31 | m_x, m_y = 0
32 32 | trio.sleep(m_y) # TRIO115
33 |- trio.sleep(m_x) # TRIO115
33 |+ trio.lowlevel.checkpoint() # TRIO115
34 34 |
35 35 | m_a = m_b = 0
36 36 | trio.sleep(m_a) # TRIO115
32 32 | trio.sleep(m_y) # OK

TRIO115.py:36:5: TRIO115 [*] Use `trio.lowlevel.checkpoint()` instead of `trio.sleep(0)`
|
Expand All @@ -195,7 +155,7 @@ TRIO115.py:36:5: TRIO115 [*] Use `trio.lowlevel.checkpoint()` instead of `trio.s
= help: Replace with `trio.lowlevel.checkpoint()`

Safe fix
33 33 | trio.sleep(m_x) # TRIO115
33 33 | trio.sleep(m_x) # OK
34 34 |
35 35 | m_a = m_b = 0
36 |- trio.sleep(m_a) # TRIO115
Expand Down Expand Up @@ -264,51 +224,88 @@ TRIO115.py:42:5: TRIO115 [*] Use `trio.lowlevel.checkpoint()` instead of `trio.s
44 44 |
45 45 | def func():

TRIO115.py:53:5: TRIO115 [*] Use `trio.lowlevel.checkpoint()` instead of `trio.sleep(0)`
TRIO115.py:48:14: TRIO115 [*] Use `trio.lowlevel.checkpoint()` instead of `trio.sleep(0)`
|
52 | def func():
53 | sleep(0) # TRIO115
| ^^^^^^^^ TRIO115
46 | import trio
47 |
48 | trio.run(trio.sleep(0)) # TRIO115
| ^^^^^^^^^^^^^ TRIO115
|
= help: Replace with `trio.lowlevel.checkpoint()`

Safe fix
46 46 | trio.run(trio.sleep(0)) # TRIO115
45 45 | def func():
46 46 | import trio
47 47 |
48 48 |
49 |-from trio import Event, sleep
49 |+from trio import Event, sleep, lowlevel
48 |- trio.run(trio.sleep(0)) # TRIO115
48 |+ trio.run(trio.lowlevel.checkpoint()) # TRIO115
49 49 |
50 50 |
51 51 | from trio import Event, sleep

TRIO115.py:55:5: TRIO115 [*] Use `trio.lowlevel.checkpoint()` instead of `trio.sleep(0)`
|
54 | def func():
55 | sleep(0) # TRIO115
| ^^^^^^^^ TRIO115
|
= help: Replace with `trio.lowlevel.checkpoint()`

Safe fix
48 48 | trio.run(trio.sleep(0)) # TRIO115
49 49 |
50 50 |
51 51 |
52 52 | def func():
53 |- sleep(0) # TRIO115
53 |+ lowlevel.checkpoint() # TRIO115
54 54 |
55 55 |
56 56 | async def func():
51 |-from trio import Event, sleep
51 |+from trio import Event, sleep, lowlevel
52 52 |
53 53 |
54 54 | def func():
55 |- sleep(0) # TRIO115
55 |+ lowlevel.checkpoint() # TRIO115
56 56 |
57 57 |
58 58 | async def func():

TRIO115.py:57:11: TRIO115 [*] Use `trio.lowlevel.checkpoint()` instead of `trio.sleep(0)`
TRIO115.py:59:11: TRIO115 [*] Use `trio.lowlevel.checkpoint()` instead of `trio.sleep(0)`
|
56 | async def func():
57 | await sleep(seconds=0) # TRIO115
58 | async def func():
59 | await sleep(seconds=0) # TRIO115
| ^^^^^^^^^^^^^^^^ TRIO115
|
= help: Replace with `trio.lowlevel.checkpoint()`

Safe fix
46 46 | trio.run(trio.sleep(0)) # TRIO115
47 47 |
48 48 |
49 |-from trio import Event, sleep
49 |+from trio import Event, sleep, lowlevel
48 48 | trio.run(trio.sleep(0)) # TRIO115
49 49 |
50 50 |
51 51 |
52 52 | def func():
51 |-from trio import Event, sleep
51 |+from trio import Event, sleep, lowlevel
52 52 |
53 53 |
54 54 | def func():
--------------------------------------------------------------------------------
54 54 |
55 55 |
56 56 | async def func():
57 |- await sleep(seconds=0) # TRIO115
57 |+ await lowlevel.checkpoint() # TRIO115
56 56 |
57 57 |
58 58 | async def func():
59 |- await sleep(seconds=0) # TRIO115
59 |+ await lowlevel.checkpoint() # TRIO115
60 60 |
61 61 |
62 62 | def func():

TRIO115.py:66:9: TRIO115 [*] Use `trio.lowlevel.checkpoint()` instead of `trio.sleep(0)`
|
65 | if (walrus := 0) == 0:
66 | trio.sleep(walrus) # TRIO115
| ^^^^^^^^^^^^^^^^^^ TRIO115
|
= help: Replace with `trio.lowlevel.checkpoint()`

Safe fix
63 63 | import trio
64 64 |
65 65 | if (walrus := 0) == 0:
66 |- trio.sleep(walrus) # TRIO115
66 |+ trio.lowlevel.checkpoint() # TRIO115


4 changes: 2 additions & 2 deletions crates/ruff_linter/src/rules/flake8_type_checking/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ pub(crate) fn is_singledispatch_implementation(
/// This requires more than just wrapping the reference itself in quotes. For example:
/// - When quoting `Series` in `Series[pd.Timestamp]`, we want `"Series[pd.Timestamp]"`.
/// - When quoting `kubernetes` in `kubernetes.SecurityContext`, we want `"kubernetes.SecurityContext"`.
/// - When quoting `Series` in `Series["pd.Timestamp"]`, we want `"Series[pd.Timestamp]"`.
/// - When quoting `Series` in `Series[Literal["pd.Timestamp"]]`, we want `"Series[Literal['pd.Timestamp']]"`.
/// - When quoting `Series` in `Series["pd.Timestamp"]`, we want `"Series[pd.Timestamp]"`. (This is currently unsupported.)
/// - When quoting `Series` in `Series[Literal["pd.Timestamp"]]`, we want `"Series[Literal['pd.Timestamp']]"`. (This is currently unsupported.)
///
/// In general, when expanding a component of a call chain, we want to quote the entire call chain.
pub(crate) fn quote_annotation(
Expand Down
Loading

0 comments on commit f3eaec7

Please sign in to comment.