Skip to content

Commit feb74a7

Browse files
authored
Merge pull request #3024 from CoolCat467/ruff-preview-mode
2 parents 8850705 + ded5cac commit feb74a7

39 files changed

+122
-95
lines changed

notes-to-self/how-does-windows-so-reuseaddr-work.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ def table_entry(mode1, bind_type1, mode2, bind_type2):
4949
"""
5050
second bind
5151
| """
52-
+ " | ".join(["%-19s" % mode for mode in modes]),
52+
+ " | ".join(f"{mode:<19}" for mode in modes),
5353
)
5454

5555
print(""" """, end="")
5656
for _ in modes:
57-
print(" | " + " | ".join(["%8s" % bind_type for bind_type in bind_types]), end="")
57+
print(
58+
" | " + " | ".join(f"{bind_type:>8}" for bind_type in bind_types),
59+
end="",
60+
)
5861

5962
print(
6063
"""
@@ -72,5 +75,5 @@ def table_entry(mode1, bind_type1, mode2, bind_type2):
7275
# print(mode1, bind_type1, mode2, bind_type2, entry)
7376
print(
7477
f"{mode1:>19} | {bind_type1:>8} | "
75-
+ " | ".join(["%8s" % entry for entry in row]),
78+
+ " | ".join(f"{entry:>8}" for entry in row),
7679
)

notes-to-self/socket-scaling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def pt(desc, *, count=total, item="socket"):
3232
now = time.perf_counter()
3333
total_ms = (now - last_time) * 1000
3434
per_us = total_ms * 1000 / count
35-
print(f"{desc}: {total_ms:.2f} ms total, {per_us:.2f} µs/{item}")
35+
print(f"{desc}: {total_ms:.2f} ms total, {per_us:.2f} μs/{item}")
3636
last_time = now
3737

3838
print(f"\n-- {total} sockets --")

notes-to-self/thread-dispatch-bench.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def main():
3030
in_q.put(lambda: None)
3131
out_q.get()
3232
end = time.monotonic()
33-
print(f"{(end - start) / COUNT * 1e6:.2f} µs/job")
33+
print(f"{(end - start) / COUNT * 1e6:.2f} μs/job")
3434

3535

3636
main()

notes-to-self/trivial-err.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
sys.stderr = sys.stdout
66

77

8-
async def child1():
8+
async def child1(): # noqa: RUF029 # async not required
99
raise ValueError
1010

1111

@@ -15,11 +15,11 @@ async def child2():
1515
nursery.start_soon(grandchild2)
1616

1717

18-
async def grandchild1():
18+
async def grandchild1(): # noqa: RUF029 # async not required
1919
raise KeyError
2020

2121

22-
async def grandchild2():
22+
async def grandchild2(): # noqa: RUF029 # async not required
2323
raise NameError("Bob")
2424

2525

notes-to-self/trivial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import trio
22

33

4-
async def foo():
4+
async def foo(): # noqa: RUF029 # await not used
55
print("in foo!")
66
return 3
77

pyproject.toml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ extend-exclude = [
102102
]
103103

104104
[tool.ruff.lint]
105+
preview = true
105106
allowed-confusables = [""]
106107

107108
select = [
@@ -147,10 +148,20 @@ extend-ignore = [
147148
# to export for public use.
148149
'src/trio/__init__.py' = ['F401']
149150
'src/trio/_core/__init__.py' = ['F401']
150-
'src/trio/abc.py' = ['F401']
151+
'src/trio/abc.py' = ['F401', 'A005']
151152
'src/trio/lowlevel.py' = ['F401']
152-
'src/trio/socket.py' = ['F401']
153+
'src/trio/socket.py' = ['F401', 'A005']
153154
'src/trio/testing/__init__.py' = ['F401']
155+
# RUF029 is ignoring tests that are marked as async functions but
156+
# do not use an await in their function bodies. There are several
157+
# places where internal trio synchronous code relies on being
158+
# called from an async function, where current task is set up.
159+
'src/trio/_tests/*.py' = ['RUF029']
160+
'src/trio/_core/_tests/*.py' = ['RUF029']
161+
# A005 is ignoring modules that shadow stdlib modules.
162+
'src/trio/_abc.py' = ['A005']
163+
'src/trio/_socket.py' = ['A005']
164+
'src/trio/_ssl.py' = ['A005']
154165

155166
[tool.ruff.lint.isort]
156167
combine-as-imports = true

src/trio/_core/_entry_queue.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ def run_cb(job: Job) -> None:
6464
sync_fn(*args)
6565
except BaseException as exc:
6666

67-
async def kill_everything(exc: BaseException) -> NoReturn:
67+
async def kill_everything( # noqa: RUF029 # await not used
68+
exc: BaseException,
69+
) -> NoReturn:
6870
raise exc
6971

7072
try:
@@ -139,7 +141,7 @@ def run_sync_soon(
139141
# wakeup call might trigger an OSError b/c the IO manager has
140142
# already been shut down.
141143
if idempotent:
142-
self.idempotent_queue[(sync_fn, args)] = None
144+
self.idempotent_queue[sync_fn, args] = None
143145
else:
144146
self.queue.append((sync_fn, args))
145147
self.wakeup.wakeup_thread_and_signal_safe()

src/trio/_core/_tests/test_asyncgen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ async def agen() -> AsyncGenerator[int, None]:
110110
await _core.wait_all_tasks_blocked()
111111
assert record == ["crashing"]
112112
# Following type ignore is because typing for LogCaptureFixture is wrong
113-
exc_type, exc_value, exc_traceback = caplog.records[0].exc_info # type: ignore[misc]
113+
exc_type, exc_value, _exc_traceback = caplog.records[0].exc_info # type: ignore[misc]
114114
assert exc_type is ValueError
115115
assert str(exc_value) == "oops"
116116
assert "during finalization of async generator" in caplog.records[0].message
@@ -227,8 +227,8 @@ async def async_main() -> None:
227227
# failure as small as we want.
228228
for _attempt in range(50):
229229
needs_retry = False
230-
del record[:]
231-
del saved[:]
230+
record.clear()
231+
saved.clear()
232232
_core.run(async_main)
233233
if needs_retry: # pragma: no cover
234234
assert record == ["cleaned up"]

src/trio/_core/_tests/test_instrumentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ async def main() -> Task:
204204
assert ("after_run", None) in r.record
205205
# And we got a log message
206206
assert caplog.records[0].exc_info is not None
207-
exc_type, exc_value, exc_traceback = caplog.records[0].exc_info
207+
exc_type, exc_value, _exc_traceback = caplog.records[0].exc_info
208208
assert exc_type is ValueError
209209
assert str(exc_value) == "oops"
210210
assert "Instrument has been disabled" in caplog.records[0].message

src/trio/_core/_tests/test_io.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ async def block_on_write() -> None:
161161

162162
@read_socket_test
163163
async def test_double_read(socketpair: SocketPair, wait_readable: WaitSocket) -> None:
164-
a, b = socketpair
164+
a, _b = socketpair
165165

166166
# You can't have two tasks trying to read from a socket at the same time
167167
async with _core.open_nursery() as nursery:
@@ -174,7 +174,7 @@ async def test_double_read(socketpair: SocketPair, wait_readable: WaitSocket) ->
174174

175175
@write_socket_test
176176
async def test_double_write(socketpair: SocketPair, wait_writable: WaitSocket) -> None:
177-
a, b = socketpair
177+
a, _b = socketpair
178178

179179
# You can't have two tasks trying to write to a socket at the same time
180180
fill_socket(a)
@@ -195,7 +195,7 @@ async def test_interrupted_by_close(
195195
wait_writable: WaitSocket,
196196
notify_closing: Callable[[stdlib_socket.socket], object],
197197
) -> None:
198-
a, b = socketpair
198+
a, _b = socketpair
199199

200200
async def reader() -> None:
201201
with pytest.raises(_core.ClosedResourceError):

0 commit comments

Comments
 (0)