refactor(core): make `trezorui_api.LayoutContext` a protocol
What changed, and why it matters
This is a small, safe code cleanup. It changes a type annotation from a concrete class to a protocol (an interface definition) and updates two function signatures to return the more general interface type. There is no change to actual program behavior, no bug fix, and no security relevance.
No action needed. This is a non-security refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors trezorui_api.LayoutContext from a Generic[T] base class to a Protocol[T], making it a structural interface. It also changes return types of show_homescreen and show_lockscreen from LayoutObj[UiResult] to LayoutContext[UiResult]. This is purely a typing/mocking change with no runtime effect.
Changed components
core/embed/rust/src/ui/api/firmware_micropython.rscore/mocks/generated/trezorui_api.pyiInspect captured patch +6 / −6
diff --git a/core/embed/rust/src/ui/api/firmware_micropython.rs b/core/embed/rust/src/ui/api/firmware_micropython.rs
index 87698456..397b8c63 100644
--- a/core/embed/rust/src/ui/api/firmware_micropython.rs
+++ b/core/embed/rust/src/ui/api/firmware_micropython.rs
@@ -1462,7 +1462,7 @@ pub static mp_module_trezorui_api: Module = obj_module! {
/// def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
/// """Exits a context manager (dropping the root component)."""
///
- /// class LayoutContext(Generic[T]):
+ /// class LayoutContext(Protocol[T]):
/// """Scopes the lifetime of a Rust-based layout object."""
///
/// def __enter__(self) -> LayoutObj[T]:
@@ -1964,7 +1964,7 @@ pub static mp_module_trezorui_api: Module = obj_module! {
/// notification: tuple[str, int, bool] | None = None,
/// lockable: bool,
/// skip_first_paint: bool,
- /// ) -> LayoutObj[UiResult]:
+ /// ) -> LayoutContext[UiResult]:
/// """Idle homescreen."""
Qstr::MP_QSTR_show_homescreen => obj_fn_kw!(0, new_show_homescreen).as_obj(),
@@ -2060,7 +2060,7 @@ pub static mp_module_trezorui_api: Module = obj_module! {
/// bootscreen: bool,
/// skip_first_paint: bool,
/// coinjoin_authorized: bool = False,
- /// ) -> LayoutObj[UiResult]:
+ /// ) -> LayoutContext[UiResult]:
/// """Homescreen for locked device."""
Qstr::MP_QSTR_show_lockscreen => obj_fn_kw!(0, new_show_lockscreen).as_obj(),
diff --git a/core/mocks/generated/trezorui_api.pyi b/core/mocks/generated/trezorui_api.pyi
index e151e60b..dec29f7d 100644
--- a/core/mocks/generated/trezorui_api.pyi
+++ b/core/mocks/generated/trezorui_api.pyi
@@ -89,7 +89,7 @@ class LayoutObj(Generic[T]):
# rust/src/ui/api/firmware_micropython.rs
-class LayoutContext(Generic[T]):
+class LayoutContext(Protocol[T]):
"""Scopes the lifetime of a Rust-based layout object."""
def __enter__(self) -> LayoutObj[T]:
"""Enters a context manager (checking the root component is not dropped)."""
@@ -623,7 +623,7 @@ def show_homescreen(
notification: tuple[str, int, bool] | None = None,
lockable: bool,
skip_first_paint: bool,
-) -> LayoutObj[UiResult]:
+) -> LayoutContext[UiResult]:
"""Idle homescreen."""
@@ -728,7 +728,7 @@ def show_lockscreen(
bootscreen: bool,
skip_first_paint: bool,
coinjoin_authorized: bool = False,
-) -> LayoutObj[UiResult]:
+) -> LayoutContext[UiResult]:
"""Homescreen for locked device."""
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.