1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-06 20:52:40 +00:00

style(python): improve type hints for input flows

This commit is contained in:
matejcik 2025-01-09 15:11:29 +01:00 committed by matejcik
parent 6a5836708f
commit 79cc7a9693
3 changed files with 9 additions and 6 deletions

View File

@ -67,6 +67,8 @@ if TYPE_CHECKING:
wait: bool | None = None, wait: bool | None = None,
) -> "LayoutContent": ... ) -> "LayoutContent": ...
InputFlowType = Generator[None, messages.ButtonRequest, None]
EXPECTED_RESPONSES_CONTEXT_LINES = 3 EXPECTED_RESPONSES_CONTEXT_LINES = 3
@ -1108,7 +1110,7 @@ class TrezorClientDebugLink(TrezorClient):
return msg return msg
def set_input_flow( def set_input_flow(
self, input_flow: Generator[None, messages.ButtonRequest | None, None] self, input_flow: InputFlowType | Callable[[], InputFlowType]
) -> None: ) -> None:
"""Configure a sequence of input events for the current with-block. """Configure a sequence of input events for the current with-block.
@ -1142,7 +1144,7 @@ class TrezorClientDebugLink(TrezorClient):
if not hasattr(input_flow, "send"): if not hasattr(input_flow, "send"):
raise RuntimeError("input_flow should be a generator function") raise RuntimeError("input_flow should be a generator function")
self.ui.input_flow = input_flow self.ui.input_flow = input_flow
input_flow.send(None) # start the generator next(input_flow) # start the generator
def watch_layout(self, watch: bool = True) -> None: def watch_layout(self, watch: bool = True) -> None:
"""Enable or disable watching layout changes. """Enable or disable watching layout changes.
@ -1190,7 +1192,8 @@ class TrezorClientDebugLink(TrezorClient):
input_flow.throw(exc_type, value, traceback) input_flow.throw(exc_type, value, traceback)
def set_expected_responses( def set_expected_responses(
self, expected: list[Union["ExpectedMessage", Tuple[bool, "ExpectedMessage"]]] self,
expected: Sequence[Union["ExpectedMessage", Tuple[bool, "ExpectedMessage"]]],
) -> None: ) -> None:
"""Set a sequence of expected responses to client calls. """Set a sequence of expected responses to client calls.

View File

@ -12,7 +12,7 @@ input flow details.
from __future__ import annotations from __future__ import annotations
import time import time
from typing import Callable, Generator from typing import Callable, Generator, Sequence
from trezorlib import messages from trezorlib import messages
from trezorlib.debuglink import DebugLink, LayoutContent, LayoutType from trezorlib.debuglink import DebugLink, LayoutContent, LayoutType
@ -2049,7 +2049,7 @@ class InputFlowSlip39BasicRecoveryDryRun(InputFlowBase):
class InputFlowSlip39BasicRecovery(InputFlowBase): class InputFlowSlip39BasicRecovery(InputFlowBase):
def __init__(self, client: Client, shares: list[str], pin: str | None = None): def __init__(self, client: Client, shares: Sequence[str], pin: str | None = None):
super().__init__(client) super().__init__(client)
self.shares = shares self.shares = shares
self.pin = pin self.pin = pin

View File

@ -301,7 +301,7 @@ class RecoveryFlow:
def input_all_slip39_shares( def input_all_slip39_shares(
self, self,
shares: list[str], shares: t.Sequence[str],
has_groups: bool = False, has_groups: bool = False,
click_info: bool = False, click_info: bool = False,
) -> BRGeneratorType: ) -> BRGeneratorType: