mirror of
https://github.com/trezor/trezor-firmware.git
synced 2026-02-20 00:33:30 +01:00
refactor(core): add type annotation to spawn() and with_context()
[no changelog]
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user