From 467c4f4f8521c29bb3851451d578267b1e37741f Mon Sep 17 00:00:00 2001 From: CoolCat467 <52022020+CoolCat467@users.noreply.github.com> Date: Sun, 3 Sep 2023 00:12:55 -0500 Subject: [PATCH 1/4] Start fixing type errors --- trio/_core/_run.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/trio/_core/_run.py b/trio/_core/_run.py index c5c16803b0..0ed5f78322 100644 --- a/trio/_core/_run.py +++ b/trio/_core/_run.py @@ -200,8 +200,7 @@ def collapse_exception_group( ) return exceptions[0] elif modified: - # derive() returns Any for some reason. - return excgroup.derive(exceptions) # type: ignore[no-any-return] + return excgroup.derive(exceptions) else: return excgroup From 90bbcf17891650ae90f493aa9aa02b3b347b8930 Mon Sep 17 00:00:00 2001 From: CoolCat467 <52022020+CoolCat467@users.noreply.github.com> Date: Sun, 3 Sep 2023 00:15:17 -0500 Subject: [PATCH 2/4] Fix formatting --- trio/_threads.py | 1 - 1 file changed, 1 deletion(-) diff --git a/trio/_threads.py b/trio/_threads.py index 2780fb6446..24905cfbde 100644 --- a/trio/_threads.py +++ b/trio/_threads.py @@ -409,7 +409,6 @@ def callback( fn: Callable[..., RetT], args: tuple[object, ...], ) -> None: - @disable_ki_protection def unprotected_fn() -> RetT: ret = fn(*args) From 556fea4ebba3ff6ddfe3f0cbad6faa6ac4925ad7 Mon Sep 17 00:00:00 2001 From: CoolCat467 <52022020+CoolCat467@users.noreply.github.com> Date: Sun, 3 Sep 2023 00:21:13 -0500 Subject: [PATCH 3/4] Fix type annotations --- trio/_core/_run.py | 9 +++++++-- trio/_core/_tests/test_run.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/trio/_core/_run.py b/trio/_core/_run.py index 0ed5f78322..c51ffd6af2 100644 --- a/trio/_core/_run.py +++ b/trio/_core/_run.py @@ -2357,7 +2357,9 @@ def my_done_callback(run_outcome): # spawn_system_task. We don't actually run any user code during # this time, so it shouldn't be possible to get an exception here, # except for a TrioInternalError. - next_send = None + next_send: EventResult = cast( + EventResult, None + ) # First iteration must be `None`, every iteration after that is EventResult for tick in range(5): # expected need is 2 iterations + leave some wiggle room if runner.system_nursery is not None: # We're initialized enough to switch to async guest ticks @@ -2378,7 +2380,10 @@ def my_done_callback(run_outcome): # IOManager.get_events() if no I/O was waiting, which is # platform-dependent. We don't actually check for I/O during # this init phase because no one should be expecting any yet. - next_send = 0 if sys.platform == "win32" else () + if sys.platform == "win32": + next_send = 0 + else: + next_send = [] else: # pragma: no cover guest_state.unrolled_run_gen.throw( TrioInternalError( diff --git a/trio/_core/_tests/test_run.py b/trio/_core/_tests/test_run.py index 0b15b606fb..5c45cf828f 100644 --- a/trio/_core/_tests/test_run.py +++ b/trio/_core/_tests/test_run.py @@ -2066,7 +2066,7 @@ def check_function_returning_coroutine() -> Awaitable[object]: sniffio.current_async_library() @contextmanager - def alternate_sniffio_library(): + def alternate_sniffio_library() -> Generator[None, None, None]: prev_token = sniffio.current_async_library_cvar.set("nullio") prev_library, sniffio.thread_local.name = sniffio.thread_local.name, "nullio" try: From dacd4b3ff415938a6a7de1fb8a0bcd9221be6a61 Mon Sep 17 00:00:00 2001 From: CoolCat467 <52022020+CoolCat467@users.noreply.github.com> Date: Sun, 3 Sep 2023 00:50:21 -0500 Subject: [PATCH 4/4] Explicit typing not required after cast --- trio/_core/_run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trio/_core/_run.py b/trio/_core/_run.py index c51ffd6af2..b2f3a65ddd 100644 --- a/trio/_core/_run.py +++ b/trio/_core/_run.py @@ -2357,7 +2357,7 @@ def my_done_callback(run_outcome): # spawn_system_task. We don't actually run any user code during # this time, so it shouldn't be possible to get an exception here, # except for a TrioInternalError. - next_send: EventResult = cast( + next_send = cast( EventResult, None ) # First iteration must be `None`, every iteration after that is EventResult for tick in range(5): # expected need is 2 iterations + leave some wiggle room