chore(core): improve `loop.Task` type annotation
What changed, and why it matters
This commit only changes Python type annotations for the loop.Task class, adding a generic type parameter [None]. It does not alter any runtime behavior, logic, or security checks in the Trezor firmware code.
No security action required. This is a routine type-annotation cleanup with no runtime effect.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit updates type hints from loop.Task to loop.Task[None] across three files: core/src/trezor/ui/init.py, core/src/trezor/ui/layouts/homescreen.py, and core/src/trezor/workflow.py. These are purely annotation changes with no functional code modifications. The [no changelog] tag in the commit message confirms this is a non-user-facing chore.
Changed components
core/src/trezor/ui/__init__.pycore/src/trezor/ui/layouts/homescreen.pycore/src/trezor/workflow.pyInspect captured patch +13 / −10
diff --git a/core/src/trezor/ui/__init__.py b/core/src/trezor/ui/__init__.py
index 3aea331d..f4402a5c 100644
--- a/core/src/trezor/ui/__init__.py
+++ b/core/src/trezor/ui/__init__.py
@@ -149,12 +149,12 @@ class Layout(Generic[T]):
def __init__(self, layout: LayoutObj[T]) -> None:
"""Set up a layout."""
self.layout = layout
- self.tasks: set[loop.Task] = set()
- self.timers: dict[int, loop.Task] = {}
+ self.tasks: set[loop.Task[None]] = set()
+ self.timers: dict[int, loop.Task[None]] = {}
self.result_box: loop.mailbox[Any] = loop.mailbox()
self.button_request_ack_pending: bool = False
self.button_request_box: loop.mailbox[ButtonRequest | None] = loop.mailbox()
- self.button_request_task: loop.Task | None = None
+ self.button_request_task: loop.Task[None] | None = None
self.transition_out: AttachType | None = None
self.backlight_level = BacklightLevels.NORMAL
self.context: Context | None = None
@@ -431,7 +431,7 @@ class Layout(Generic[T]):
self.result_box.put(msg)
raise Shutdown()
- def create_tasks(self) -> Iterator[loop.Task]:
+ def create_tasks(self) -> Iterator[loop.Task[None]]:
"""Set up background tasks for a layout.
Called from `start()`. Creates and yields a list of background tasks, typically
@@ -533,7 +533,7 @@ class Layout(Generic[T]):
finally:
pm.close()
- def _task_finalizer(self, task: loop.Task, value: Any) -> None:
+ def _task_finalizer(self, task: loop.Task[None], value: Any) -> None:
if value is None:
# all is good
if __debug__:
@@ -559,7 +559,7 @@ class Layout(Generic[T]):
if __debug__:
log.error(__name__, "UI task returned non-None: %s (%s)", task, value)
- def _start_task(self, task: loop.Task) -> None:
+ def _start_task(self, task: loop.Task[None]) -> None:
self.tasks.add(task)
loop.schedule(task, finalizer=self._task_finalizer)
diff --git a/core/src/trezor/ui/layouts/homescreen.py b/core/src/trezor/ui/layouts/homescreen.py
index b54efb4d..de9adc13 100644
--- a/core/src/trezor/ui/layouts/homescreen.py
+++ b/core/src/trezor/ui/layouts/homescreen.py
@@ -49,7 +49,7 @@ class UsbAwareLayout(ui.Layout):
event = await usbcheck
self._event(self.layout.usb_event, event)
- def create_tasks(self) -> Iterator[loop.Task]:
+ def create_tasks(self) -> Iterator[loop.Task[None]]:
yield from super().create_tasks()
yield self.usb_checker_task()
diff --git a/core/src/trezor/workflow.py b/core/src/trezor/workflow.py
index 7540af85..d13c689c 100644
--- a/core/src/trezor/workflow.py
+++ b/core/src/trezor/workflow.py
@@ -49,7 +49,7 @@ tasks: set[loop.spawn] = set()
default_task: loop.spawn | None = None
# Constructor for the default workflow. Returns a workflow task.
-default_constructor: Callable[[], loop.Task] | None = None
+default_constructor: Callable[[], loop.Task[None]] | None = None
# Determines whether idle timer firing closes currently running workflow. Storage is locked always.
autolock_interrupts_workflow: bool = True
@@ -127,7 +127,10 @@ def start_default() -> None:
autolock_interrupts_workflow = True
-def set_default(constructor: Callable[[], loop.Task], restart: bool = False) -> None:
+def set_default(
+ constructor: Callable[[], loop.Task[None]],
+ restart: bool = False,
+) -> None:
"""Configure a default workflow, which will be started next time it is needed."""
global default_constructor
if __debug__:
@@ -206,7 +209,7 @@ class IdleTimer:
def __init__(self) -> None:
self.timeouts: dict[IdleCallback, int] = {}
- self.tasks: dict[IdleCallback, loop.Task] = {}
+ self.tasks: dict[IdleCallback, loop.Task[None]] = {}
async def _timeout_task(self, callback: IdleCallback) -> None:
# This function is async, so the result of self._timeout_task() is an awaitable,
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.