From c07d37c82266a7bf518b9be8187dfe2b31a3aa7d Mon Sep 17 00:00:00 2001 From: matejcik Date: Thu, 26 Sep 2024 15:14:12 +0200 Subject: [PATCH] style: make style_check passing --- core/embed/rust/src/ui/component/base.rs | 6 ++---- core/embed/rust/src/ui/component/button_request.rs | 2 +- core/embed/rust/src/ui/layout/obj.rs | 5 ++++- core/embed/rust/src/ui/model_mercury/layout.rs | 5 ++++- core/embed/rust/src/ui/model_tr/layout.rs | 5 ++++- .../rust/src/ui/model_tt/component/keyboard/common.rs | 4 +++- core/embed/rust/src/ui/model_tt/layout.rs | 7 +++++-- core/src/apps/common/sdcard.py | 2 +- core/src/apps/ethereum/sign_tx.py | 1 - core/src/apps/management/recovery_device/layout.py | 3 +-- core/src/trezor/ui/layouts/mercury/__init__.py | 7 +++---- core/src/trezor/ui/layouts/mercury/fido.py | 2 -- core/src/trezor/ui/layouts/mercury/recovery.py | 2 +- core/src/trezor/ui/layouts/tr/__init__.py | 2 +- python/src/trezorlib/debuglink.py | 2 +- 15 files changed, 31 insertions(+), 24 deletions(-) diff --git a/core/embed/rust/src/ui/component/base.rs b/core/embed/rust/src/ui/component/base.rs index 4fe0a60314..10faf12e5d 100644 --- a/core/embed/rust/src/ui/component/base.rs +++ b/core/embed/rust/src/ui/component/base.rs @@ -582,8 +582,7 @@ impl EventCtx { } pub fn send_button_request(&mut self, code: ButtonRequestCode, name: TString<'static>) { - #[cfg(feature = "ui_debug")] - assert!(self.button_request.is_none()); + debug_assert!(self.button_request.is_none()); self.button_request = Some(ButtonRequest::new(code, name)); } @@ -612,8 +611,7 @@ impl EventCtx { } pub fn clear(&mut self) { - #[cfg(feature = "ui_debug")] - assert!(self.button_request.is_none()); + debug_assert!(self.button_request.is_none()); // replace self with a new instance, keeping only the fields we care about *self = Self::new(); } diff --git a/core/embed/rust/src/ui/component/button_request.rs b/core/embed/rust/src/ui/component/button_request.rs index 273f9858ed..529f2b3e0f 100644 --- a/core/embed/rust/src/ui/component/button_request.rs +++ b/core/embed/rust/src/ui/component/button_request.rs @@ -53,7 +53,7 @@ impl Component for SendButtonRequest { } } SendButtonRequestPolicy::OnAttachAlways => { - if let Some(br) = self.button_request.clone() { + if let Some(br) = self.button_request { ctx.send_button_request(br.code, br.name); } } diff --git a/core/embed/rust/src/ui/layout/obj.rs b/core/embed/rust/src/ui/layout/obj.rs index 9d780a40f1..2c1f4115c5 100644 --- a/core/embed/rust/src/ui/layout/obj.rs +++ b/core/embed/rust/src/ui/layout/obj.rs @@ -30,7 +30,10 @@ use crate::{ time::Duration, ui::{ button_request::ButtonRequest, - component::{base::{AttachType, TimerToken}, Component, Event, EventCtx, Never}, + component::{ + base::{AttachType, TimerToken}, + Component, Event, EventCtx, Never, + }, display, event::USBEvent, ui_features::ModelUI, diff --git a/core/embed/rust/src/ui/model_mercury/layout.rs b/core/embed/rust/src/ui/model_mercury/layout.rs index 278b8bf1e1..4c2cd4250c 100644 --- a/core/embed/rust/src/ui/model_mercury/layout.rs +++ b/core/embed/rust/src/ui/model_mercury/layout.rs @@ -43,7 +43,10 @@ use crate::{ flow::Swipable, geometry::{self, Direction}, layout::{ - base::LAYOUT_STATE, obj::{ComponentMsgObj, LayoutObj, ATTACH_TYPE_OBJ}, result::{CANCELLED, CONFIRMED, INFO}, util::{upy_disable_animation, ConfirmBlob, PropsList, RecoveryType} + base::LAYOUT_STATE, + obj::{ComponentMsgObj, LayoutObj, ATTACH_TYPE_OBJ}, + result::{CANCELLED, CONFIRMED, INFO}, + util::{upy_disable_animation, ConfirmBlob, PropsList, RecoveryType}, }, model_mercury::{ component::{check_homescreen_format, SwipeContent}, diff --git a/core/embed/rust/src/ui/model_tr/layout.rs b/core/embed/rust/src/ui/model_tr/layout.rs index 9775d4f937..a85d182341 100644 --- a/core/embed/rust/src/ui/model_tr/layout.rs +++ b/core/embed/rust/src/ui/model_tr/layout.rs @@ -47,7 +47,10 @@ use crate::{ }, geometry, layout::{ - base::LAYOUT_STATE, obj::{ComponentMsgObj, LayoutObj, ATTACH_TYPE_OBJ}, result::{CANCELLED, CONFIRMED, INFO}, util::{upy_disable_animation, ConfirmBlob, RecoveryType} + base::LAYOUT_STATE, + obj::{ComponentMsgObj, LayoutObj, ATTACH_TYPE_OBJ}, + result::{CANCELLED, CONFIRMED, INFO}, + util::{upy_disable_animation, ConfirmBlob, RecoveryType}, }, model_tr::component::check_homescreen_format, }, diff --git a/core/embed/rust/src/ui/model_tt/component/keyboard/common.rs b/core/embed/rust/src/ui/model_tt/component/keyboard/common.rs index b222745361..fe2d558589 100644 --- a/core/embed/rust/src/ui/model_tt/component/keyboard/common.rs +++ b/core/embed/rust/src/ui/model_tt/component/keyboard/common.rs @@ -58,7 +58,9 @@ impl MultiTapKeyboard { /// Returns `true` if `event` is an `Event::Timer` for the currently pending /// timer. pub fn timeout_event(&mut self, event: Event) -> bool { - self.pending.as_mut().map_or(false, |t| t.timer.expire(event)) + self.pending + .as_mut() + .map_or(false, |t| t.timer.expire(event)) } /// Reset to the empty state. Takes `EventCtx` to request a paint pass (to diff --git a/core/embed/rust/src/ui/model_tt/layout.rs b/core/embed/rust/src/ui/model_tt/layout.rs index be45d3644d..41165cd728 100644 --- a/core/embed/rust/src/ui/model_tt/layout.rs +++ b/core/embed/rust/src/ui/model_tt/layout.rs @@ -50,7 +50,10 @@ use crate::{ }, geometry, layout::{ - base::LAYOUT_STATE, obj::{ComponentMsgObj, LayoutObj, ATTACH_TYPE_OBJ}, result::{CANCELLED, CONFIRMED, INFO}, util::{upy_disable_animation, ConfirmBlob, PropsList, RecoveryType} + base::LAYOUT_STATE, + obj::{ComponentMsgObj, LayoutObj, ATTACH_TYPE_OBJ}, + result::{CANCELLED, CONFIRMED, INFO}, + util::{upy_disable_animation, ConfirmBlob, PropsList, RecoveryType}, }, model_tt::component::check_homescreen_format, }, @@ -1692,7 +1695,7 @@ pub static mp_module_trezorui2: Module = obj_module! { /// /// def get_transition_out(self) -> AttachType: /// """Return the transition type.""" - /// + /// /// def return_value(self) -> T: /// """Retrieve the return value of the layout object.""" /// diff --git a/core/src/apps/common/sdcard.py b/core/src/apps/common/sdcard.py index 3713030226..6246d05abe 100644 --- a/core/src/apps/common/sdcard.py +++ b/core/src/apps/common/sdcard.py @@ -1,4 +1,4 @@ -from trezor import TR, io, utils, wire +from trezor import TR, io, wire from trezor.ui.layouts import confirm_action, show_error_and_raise from trezor.utils import sd_hotswap_enabled diff --git a/core/src/apps/ethereum/sign_tx.py b/core/src/apps/ethereum/sign_tx.py index 743d554de6..38e99b2939 100644 --- a/core/src/apps/ethereum/sign_tx.py +++ b/core/src/apps/ethereum/sign_tx.py @@ -1,6 +1,5 @@ from typing import TYPE_CHECKING -from trezor import utils from trezor.crypto import rlp from trezor.messages import EthereumTxRequest from trezor.utils import BufferReader diff --git a/core/src/apps/management/recovery_device/layout.py b/core/src/apps/management/recovery_device/layout.py index 8d00a9ead1..352cf2d47e 100644 --- a/core/src/apps/management/recovery_device/layout.py +++ b/core/src/apps/management/recovery_device/layout.py @@ -1,7 +1,6 @@ from typing import TYPE_CHECKING from trezor import TR -from trezor.enums import ButtonRequestType from trezor.ui.layouts.recovery import ( # noqa: F401 request_word_count, show_group_share_success, @@ -11,7 +10,7 @@ from trezor.ui.layouts.recovery import ( # noqa: F401 from apps.common import backup_types if TYPE_CHECKING: - from typing import Awaitable, Callable + from typing import Awaitable from trezor.enums import BackupType diff --git a/core/src/trezor/ui/layouts/mercury/__init__.py b/core/src/trezor/ui/layouts/mercury/__init__.py index bfcbf1ce4c..864d601cf4 100644 --- a/core/src/trezor/ui/layouts/mercury/__init__.py +++ b/core/src/trezor/ui/layouts/mercury/__init__.py @@ -1,15 +1,14 @@ from typing import TYPE_CHECKING import trezorui2 -from trezor import TR, io, loop, ui, utils +from trezor import TR, ui, utils from trezor.enums import ButtonRequestType -from trezor.messages import ButtonAck, ButtonRequest -from trezor.wire import ActionCancelled, context +from trezor.wire import ActionCancelled from ..common import draw_simple, interact, raise_if_not_confirmed, with_info if TYPE_CHECKING: - from typing import Any, Awaitable, Iterable, NoReturn, Sequence, TypeVar + from typing import Awaitable, Iterable, NoReturn, Sequence, TypeVar from ..common import ExceptionType, PropertyType diff --git a/core/src/trezor/ui/layouts/mercury/fido.py b/core/src/trezor/ui/layouts/mercury/fido.py index d74df0619e..098744e65d 100644 --- a/core/src/trezor/ui/layouts/mercury/fido.py +++ b/core/src/trezor/ui/layouts/mercury/fido.py @@ -1,5 +1,3 @@ -from typing import TYPE_CHECKING - import trezorui2 from trezor import ui from trezor.enums import ButtonRequestType diff --git a/core/src/trezor/ui/layouts/mercury/recovery.py b/core/src/trezor/ui/layouts/mercury/recovery.py index 095ee0dac0..e809799887 100644 --- a/core/src/trezor/ui/layouts/mercury/recovery.py +++ b/core/src/trezor/ui/layouts/mercury/recovery.py @@ -1,7 +1,7 @@ from typing import TYPE_CHECKING import trezorui2 -from trezor import TR, ui +from trezor import TR from trezor.enums import ButtonRequestType, RecoveryType from ..common import interact diff --git a/core/src/trezor/ui/layouts/tr/__init__.py b/core/src/trezor/ui/layouts/tr/__init__.py index 7d21e1fdf2..4c4d384462 100644 --- a/core/src/trezor/ui/layouts/tr/__init__.py +++ b/core/src/trezor/ui/layouts/tr/__init__.py @@ -8,7 +8,7 @@ from trezor.wire import ActionCancelled from ..common import draw_simple, interact, raise_if_not_confirmed if TYPE_CHECKING: - from typing import Any, Awaitable, Iterable, NoReturn, Sequence + from typing import Awaitable, Iterable, NoReturn, Sequence from ..common import ExceptionType, PropertyType diff --git a/python/src/trezorlib/debuglink.py b/python/src/trezorlib/debuglink.py index 1aa4d99098..c5373d2b00 100644 --- a/python/src/trezorlib/debuglink.py +++ b/python/src/trezorlib/debuglink.py @@ -48,7 +48,7 @@ from .client import TrezorClient from .exceptions import TrezorFailure from .log import DUMP_BYTES from .messages import DebugWaitType -from .tools import expect, session +from .tools import expect if TYPE_CHECKING: from typing_extensions import Protocol