refactor(core): add type annotation to spawn() and with_context()

[no changelog]
This commit is contained in:
Roman Zeyde
2026-02-19 10:17:55 +01:00
parent 58850b849b
commit 62ae175382
2 changed files with 4 additions and 3 deletions

View File

@@ -112,7 +112,7 @@ if utils.USE_THP:
return ctx.channel
def with_context(ctx: Context, workflow: loop.Task) -> Generator:
def with_context(ctx: Context, workflow: loop.Task[T]) -> Generator[Any, Any, T]:
"""Run a workflow in a particular context.
Stores the context in a closure and installs it into the global variable every time

View File

@@ -6,9 +6,10 @@ from trezor import log, loop, utils
from trezor.enums import MessageType
if TYPE_CHECKING:
from typing import Callable
from typing import Callable, TypeVar
IdleCallback = Callable[[], None]
T = TypeVar("T")
if __debug__:
# Used in `on_close` below for memory statistics.
@@ -81,7 +82,7 @@ def _on_close(workflow: loop.spawn) -> None:
micropython.mem_info()
def spawn(workflow: loop.Task) -> loop.spawn:
def spawn(workflow: loop.Task[T]) -> loop.spawn[T]:
"""Spawn a workflow task.
Creates an instance of loop.spawn for the workflow and registers it into the