Skip to content

Commit d2a4031

Browse files
committed
Disable RUF029 in test files
1 parent ad10b07 commit d2a4031

25 files changed

+138
-179
lines changed

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ extend-ignore = [
152152
'src/trio/lowlevel.py' = ['F401']
153153
'src/trio/socket.py' = ['F401']
154154
'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']
155161

156162
[tool.ruff.lint.isort]
157163
combine-as-imports = true

src/trio/_core/_tests/test_asyncgen.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ def test_last_minute_gc_edge_case() -> None:
189189
record = []
190190
needs_retry = True
191191

192-
# async function missing await
193-
async def agen() -> AsyncGenerator[int, None]: # noqa: RUF029
192+
async def agen() -> AsyncGenerator[int, None]:
194193
try:
195194
yield 1
196195
finally:
@@ -271,12 +270,10 @@ def abort_fn(_: _core.RaiseCancelT) -> _core.Abort:
271270
async def test_fallback_when_no_hook_claims_it(
272271
capsys: pytest.CaptureFixture[str],
273272
) -> None:
274-
# async function missing await
275-
async def well_behaved() -> AsyncGenerator[int, None]: # noqa: RUF029
273+
async def well_behaved() -> AsyncGenerator[int, None]:
276274
yield 42
277275

278-
# async function missing await
279-
async def yields_after_yield() -> AsyncGenerator[int, None]: # noqa: RUF029
276+
async def yields_after_yield() -> AsyncGenerator[int, None]:
280277
with pytest.raises(GeneratorExit):
281278
yield 42
282279
yield 100

src/trio/_core/_tests/test_guest_mode.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ async def trio_return(in_host: InHost) -> str:
118118

119119
assert trivial_guest_run(trio_return) == "ok"
120120

121-
async def trio_fail( # noqa: RUF029 # async function missing await
121+
async def trio_fail(
122122
in_host: InHost,
123123
) -> NoReturn:
124124
raise KeyError("whoopsiedaisy")
@@ -256,7 +256,7 @@ async def synchronize() -> None:
256256
def test_warn_set_wakeup_fd_overwrite() -> None:
257257
assert signal.set_wakeup_fd(-1) == -1
258258

259-
async def trio_main( # noqa: RUF029 # async function missing await
259+
async def trio_main(
260260
in_host: InHost,
261261
) -> str:
262262
return "ok"
@@ -299,8 +299,8 @@ async def trio_main( # noqa: RUF029 # async function missing await
299299
# then it's left alone and there's no warning
300300
signal.set_wakeup_fd(a.fileno())
301301
try:
302-
# async function missing await
303-
async def trio_check_wakeup_fd_unaltered( # noqa: RUF029
302+
303+
async def trio_check_wakeup_fd_unaltered(
304304
in_host: InHost,
305305
) -> str:
306306
fd = signal.set_wakeup_fd(-1)
@@ -600,8 +600,7 @@ async def trio_main(in_host: InHost) -> None:
600600
# Also check chaining in the case where KI is injected after main exits
601601
final_exc = KeyError("whoa")
602602

603-
# async function missing await
604-
async def trio_main_raising(in_host: InHost) -> NoReturn: # noqa: RUF029
603+
async def trio_main_raising(in_host: InHost) -> NoReturn:
605604
in_host(partial(signal_raise, signal.SIGINT))
606605
raise final_exc
607606

src/trio/_core/_tests/test_instrumentation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def task_spawned(self, task: Task) -> None:
168168
def task_exited(self, task: Task) -> None:
169169
record.append(("exited", task))
170170

171-
async def main() -> Task: # noqa: RUF029 # async function missing await
171+
async def main() -> Task:
172172
return _core.current_task()
173173

174174
main_task = _core.run(main, instruments=[SpawnExitRecorder()])
@@ -191,7 +191,7 @@ def close(self) -> None:
191191
# works right.
192192
record.append("closed") # pragma: no cover
193193

194-
async def main() -> Task: # noqa: RUF029 # async function missing await
194+
async def main() -> Task:
195195
record.append("main ran")
196196
return _core.current_task()
197197

@@ -254,7 +254,7 @@ def task_exited(self, task: Task) -> NoReturn:
254254
def after_run(self) -> NoReturn:
255255
raise ValueError("oops")
256256

257-
async def main() -> None: # noqa: RUF029 # async function missing await
257+
async def main() -> None:
258258
with pytest.raises(ValueError, match="^oops$"):
259259
_core.add_instrument(EvilInstrument())
260260

src/trio/_core/_tests/test_io.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,7 @@ async def receiver(sock: stdlib_socket.socket, key: str) -> None:
301301
assert results["send_b"] == results["recv_a"]
302302

303303

304-
# async function missing await
305-
async def test_notify_closing_on_invalid_object() -> None: # noqa: RUF029
304+
async def test_notify_closing_on_invalid_object() -> None:
306305
# It should either be a no-op (generally on Unix, where we don't know
307306
# which fds are valid), or an OSError (on Windows, where we currently only
308307
# support sockets, so we have to do some validation to figure out whether

src/trio/_core/_tests/test_ki.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async def aprotected() -> None:
6767
await aunprotected()
6868

6969
@_core.disable_ki_protection
70-
async def aunprotected() -> None: # noqa: RUF029 # async fn missing await
70+
async def aunprotected() -> None:
7171
assert not _core.currently_ki_protected()
7272

7373
await aprotected()
@@ -128,8 +128,7 @@ async def child(expected: bool) -> None:
128128

129129
# This also used to be broken due to
130130
# https://bugs.python.org/issue29590
131-
# async function missing await
132-
async def test_generator_based_context_manager_throw() -> None: # noqa: RUF029
131+
async def test_generator_based_context_manager_throw() -> None:
133132
@contextlib.contextmanager
134133
@_core.enable_ki_protection
135134
def protected_manager() -> Iterator[None]:
@@ -196,18 +195,16 @@ async def agen_unprotected2() -> None:
196195

197196
async def test_native_agen_protection() -> None:
198197
# Native async generators
199-
# async function missing await
200198
@_core.enable_ki_protection
201-
async def agen_protected() -> AsyncIterator[None]: # noqa: RUF029
199+
async def agen_protected() -> AsyncIterator[None]:
202200
assert _core.currently_ki_protected()
203201
try:
204202
yield
205203
finally:
206204
assert _core.currently_ki_protected()
207205

208-
# async function missing await
209206
@_core.disable_ki_protection
210-
async def agen_unprotected() -> AsyncIterator[None]: # noqa: RUF029
207+
async def agen_unprotected() -> AsyncIterator[None]:
211208
assert not _core.currently_ki_protected()
212209
try:
213210
yield
@@ -324,9 +321,7 @@ async def check_protected_kill() -> None:
324321
# error, then kill)
325322
print("check 3")
326323

327-
async def check_kill_during_shutdown() -> ( # noqa: RUF029 # async fn missing await
328-
None
329-
):
324+
async def check_kill_during_shutdown() -> None:
330325
token = _core.current_trio_token()
331326

332327
def kill_during_shutdown() -> None:
@@ -431,7 +426,7 @@ def abort(raise_cancel: RaiseCancelT) -> Abort:
431426
print("check 9")
432427

433428
@_core.enable_ki_protection
434-
async def main_6() -> None: # noqa: RUF029 # async function missing await
429+
async def main_6() -> None:
435430
ki_self()
436431

437432
with pytest.raises(KeyboardInterrupt):
@@ -490,7 +485,7 @@ def test_ki_is_good_neighbor() -> None:
490485
def my_handler(signum: object, frame: object) -> None: # pragma: no cover
491486
pass
492487

493-
async def main() -> None: # noqa: RUF029 # async function missing await
488+
async def main() -> None:
494489
signal.signal(signal.SIGINT, my_handler)
495490

496491
_core.run(main)
@@ -514,7 +509,7 @@ def test_ki_with_broken_threads() -> None:
514509
del threading._active[thread.ident] # type: ignore[attr-defined]
515510

516511
@_core.enable_ki_protection
517-
async def inner() -> None: # noqa: RUF029 # async function missing await
512+
async def inner() -> None:
518513
assert signal.getsignal(signal.SIGINT) != signal.default_int_handler
519514

520515
_core.run(inner)

src/trio/_core/_tests/test_local.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_runvar_smoketest() -> None:
1313

1414
assert repr(t1) == "<RunVar name='test1'>"
1515

16-
async def first_check() -> None: # noqa: RUF029 # async function missing await
16+
async def first_check() -> None:
1717
with pytest.raises(LookupError):
1818
t1.get()
1919

@@ -26,7 +26,7 @@ async def first_check() -> None: # noqa: RUF029 # async function missing await
2626
assert t2.get() == "goldfish"
2727
assert t2.get(default="tuna") == "goldfish"
2828

29-
async def second_check() -> None: # noqa: RUF029 # async function missing await
29+
async def second_check() -> None:
3030
with pytest.raises(LookupError):
3131
t1.get()
3232

@@ -41,7 +41,7 @@ def test_runvar_resetting() -> None:
4141
t2 = RunVar[str]("test2", default="dogfish")
4242
t3 = RunVar[str]("test3")
4343

44-
async def reset_check() -> None: # noqa: RUF029 # async function missing await
44+
async def reset_check() -> None:
4545
token = t1.set("moonfish")
4646
assert t1.get() == "moonfish"
4747
t1.reset(token)
@@ -73,12 +73,11 @@ def test_runvar_sync() -> None:
7373
t1 = RunVar[str]("test1")
7474

7575
async def sync_check() -> None:
76-
async def task1() -> None: # noqa: RUF029 # async fn missing await
76+
async def task1() -> None:
7777
t1.set("plaice")
7878
assert t1.get() == "plaice"
7979

80-
# async function missing await
81-
async def task2(tok: RunVarToken[str]) -> None: # noqa: RUF029
80+
async def task2(tok: RunVarToken[str]) -> None:
8281
t1.reset(tok)
8382

8483
with pytest.raises(LookupError):
@@ -110,7 +109,7 @@ def test_accessing_runvar_outside_run_call_fails() -> None:
110109
with pytest.raises(RuntimeError):
111110
t1.get()
112111

113-
async def get_token() -> RunVarToken[str]: # noqa: RUF029 # async fn missing await
112+
async def get_token() -> RunVarToken[str]:
114113
return t1.set("ok")
115114

116115
token = run(get_token)

0 commit comments

Comments
 (0)