diff --git a/core/embed/rust/src/ui/model_tr/layout.rs b/core/embed/rust/src/ui/model_tr/layout.rs index 5753e44e6c..e76cf25d25 100644 --- a/core/embed/rust/src/ui/model_tr/layout.rs +++ b/core/embed/rust/src/ui/model_tr/layout.rs @@ -1877,7 +1877,7 @@ pub static mp_module_trezorui2: Module = obj_module! { /// title: str, /// button: str, /// info_button: str, # unused on TR - /// items: Iterable[Tuple[int, str]], + /// items: Iterable[Tuple[int, str | bytes]], /// verb_cancel: str | None = None, /// ) -> LayoutObj[UiResult]: /// """Confirm given items but with third button. Always single page @@ -1888,7 +1888,7 @@ pub static mp_module_trezorui2: Module = obj_module! { /// *, /// title: str, /// button: str, - /// items: Iterable[tuple[int, str]], + /// items: Iterable[tuple[int, str | bytes]], /// ) -> object: /// """Confirm long content with the possibility to go back from any page. /// Meant to be used with confirm_with_info.""" diff --git a/core/embed/rust/src/ui/model_tt/layout.rs b/core/embed/rust/src/ui/model_tt/layout.rs index 2bcb177289..f874973ebc 100644 --- a/core/embed/rust/src/ui/model_tt/layout.rs +++ b/core/embed/rust/src/ui/model_tt/layout.rs @@ -1947,7 +1947,7 @@ pub static mp_module_trezorui2: Module = obj_module! { /// title: str, /// button: str, /// info_button: str, - /// items: Iterable[tuple[int, str]], + /// items: Iterable[tuple[int, str | bytes]], /// ) -> LayoutObj[UiResult]: /// """Confirm given items but with third button. Always single page /// without scrolling.""" @@ -1957,7 +1957,7 @@ pub static mp_module_trezorui2: Module = obj_module! { /// *, /// title: str, /// button: str, - /// items: Iterable[tuple[int, str]], + /// items: Iterable[tuple[int, str | bytes]], /// ) -> LayoutObj[UiResult]: /// """Confirm long content with the possibility to go back from any page. /// Meant to be used with confirm_with_info.""" diff --git a/core/mocks/generated/trezorui2.pyi b/core/mocks/generated/trezorui2.pyi index 00e6279a94..a7b1afc352 100644 --- a/core/mocks/generated/trezorui2.pyi +++ b/core/mocks/generated/trezorui2.pyi @@ -257,7 +257,7 @@ def confirm_with_info( title: str, button: str, info_button: str, # unused on TR - items: Iterable[Tuple[int, str]], + items: Iterable[Tuple[int, str | bytes]], verb_cancel: str | None = None, ) -> LayoutObj[UiResult]: """Confirm given items but with third button. Always single page @@ -269,7 +269,7 @@ def confirm_more( *, title: str, button: str, - items: Iterable[tuple[int, str]], + items: Iterable[tuple[int, str | bytes]], ) -> object: """Confirm long content with the possibility to go back from any page. Meant to be used with confirm_with_info.""" @@ -768,7 +768,7 @@ def confirm_with_info( title: str, button: str, info_button: str, - items: Iterable[tuple[int, str]], + items: Iterable[tuple[int, str | bytes]], ) -> LayoutObj[UiResult]: """Confirm given items but with third button. Always single page without scrolling.""" @@ -779,7 +779,7 @@ def confirm_more( *, title: str, button: str, - items: Iterable[tuple[int, str]], + items: Iterable[tuple[int, str | bytes]], ) -> LayoutObj[UiResult]: """Confirm long content with the possibility to go back from any page. Meant to be used with confirm_with_info.""" diff --git a/core/src/apps/base.py b/core/src/apps/base.py index 057ffa8dc5..428d186b3c 100644 --- a/core/src/apps/base.py +++ b/core/src/apps/base.py @@ -418,7 +418,7 @@ def get_pinlocked_handler( if msg_type in workflow.ALLOW_WHILE_LOCKED: return orig_handler - async def wrapper(msg: wire.Msg) -> protobuf.MessageType: + async def wrapper(msg: protobuf.MessageType) -> protobuf.MessageType: await unlock_device() return await orig_handler(msg) @@ -442,7 +442,7 @@ def boot() -> None: MT = MessageType # local_cache_global # Register workflow handlers - for msg_type, handler in ( + for msg_type, handler in [ (MT.Initialize, handle_Initialize), (MT.GetFeatures, handle_GetFeatures), (MT.Cancel, handle_Cancel), @@ -453,8 +453,8 @@ def boot() -> None: (MT.UnlockPath, handle_UnlockPath), (MT.CancelAuthorization, handle_CancelAuthorization), (MT.SetBusy, handle_SetBusy), - ): - workflow_handlers.register(msg_type, handler) # type: ignore [cannot be assigned to type] + ]: + workflow_handlers.register(msg_type, handler) reload_settings_from_storage() if config.is_unlocked(): diff --git a/core/src/apps/bitcoin/common.py b/core/src/apps/bitcoin/common.py index d1d011db38..aa8d560597 100644 --- a/core/src/apps/bitcoin/common.py +++ b/core/src/apps/bitcoin/common.py @@ -46,7 +46,8 @@ class SigHashType(IntEnum): @classmethod def from_int(cls, sighash_type: int) -> "SigHashType": - for val in cls.__dict__.values(): # type: SigHashType + val: SigHashType + for val in cls.__dict__.values(): if val == sighash_type: return val raise ValueError("Unsupported sighash type.") diff --git a/core/src/apps/bitcoin/keychain.py b/core/src/apps/bitcoin/keychain.py index 136fb9b017..13c81d22d2 100644 --- a/core/src/apps/bitcoin/keychain.py +++ b/core/src/apps/bitcoin/keychain.py @@ -316,7 +316,7 @@ def _get_unlock_schemas( def with_keychain(func: HandlerWithCoinInfo[MsgOut]) -> Handler[MsgIn, MsgOut]: async def wrapper( - msg: MsgIn, + msg: BitcoinMessage, auth_msg: MessageType | None = None, ) -> MsgOut: coin = _get_coin_by_name(msg.coin_name) diff --git a/core/src/apps/bitcoin/sign_tx/helpers.py b/core/src/apps/bitcoin/sign_tx/helpers.py index 853be70176..a27ef12387 100644 --- a/core/src/apps/bitcoin/sign_tx/helpers.py +++ b/core/src/apps/bitcoin/sign_tx/helpers.py @@ -241,80 +241,80 @@ class UiConfirmMultipleAccounts(UiConfirm): return layout.confirm_multiple_accounts() -def confirm_output(output: TxOutput, coin: CoinInfo, amount_unit: AmountUnit, output_index: int, chunkify: bool) -> Awaitable[None]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmOutput(output, coin, amount_unit, output_index, chunkify)) +def confirm_output(output: TxOutput, coin: CoinInfo, amount_unit: AmountUnit, output_index: int, chunkify: bool) -> Awaitable[None]: # type: ignore [awaitable-return-type] + return (yield UiConfirmOutput(output, coin, amount_unit, output_index, chunkify)) # type: ignore [awaitable-return-type] -def confirm_decred_sstx_submission(output: TxOutput, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[None]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmDecredSSTXSubmission(output, coin, amount_unit)) +def confirm_decred_sstx_submission(output: TxOutput, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[None]: # type: ignore [awaitable-return-type] + return (yield UiConfirmDecredSSTXSubmission(output, coin, amount_unit)) # type: ignore [awaitable-return-type] -def should_show_payment_request_details(payment_req: TxAckPaymentRequest, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[bool]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmPaymentRequest(payment_req, coin, amount_unit)) +def should_show_payment_request_details(payment_req: TxAckPaymentRequest, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[bool]: # type: ignore [awaitable-return-type] + return (yield UiConfirmPaymentRequest(payment_req, coin, amount_unit)) # type: ignore [awaitable-return-type] -def confirm_replacement(description: str, txid: bytes) -> Awaitable[Any]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmReplacement(description, txid)) +def confirm_replacement(description: str, txid: bytes) -> Awaitable[Any]: # type: ignore [awaitable-return-type] + return (yield UiConfirmReplacement(description, txid)) # type: ignore [awaitable-return-type] -def confirm_modify_output(txo: TxOutput, orig_txo: TxOutput, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[Any]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmModifyOutput(txo, orig_txo, coin, amount_unit)) +def confirm_modify_output(txo: TxOutput, orig_txo: TxOutput, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[Any]: # type: ignore [awaitable-return-type] + return (yield UiConfirmModifyOutput(txo, orig_txo, coin, amount_unit)) # type: ignore [awaitable-return-type] -def confirm_modify_fee(title: str, user_fee_change: int, total_fee_new: int, fee_rate: float, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[Any]: # type: ignore [awaitable-is-generator] +def confirm_modify_fee(title: str, user_fee_change: int, total_fee_new: int, fee_rate: float, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[Any]: # type: ignore [awaitable-return-type] return ( - yield UiConfirmModifyFee( + yield UiConfirmModifyFee( # type: ignore [awaitable-return-type] title, user_fee_change, total_fee_new, fee_rate, coin, amount_unit ) ) -def confirm_total(spending: int, fee: int, fee_rate: float, coin: CoinInfo, amount_unit: AmountUnit, address_n: Bip32Path | None) -> Awaitable[None]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmTotal(spending, fee, fee_rate, coin, amount_unit, address_n)) +def confirm_total(spending: int, fee: int, fee_rate: float, coin: CoinInfo, amount_unit: AmountUnit, address_n: Bip32Path | None) -> Awaitable[None]: # type: ignore [awaitable-return-type] + return (yield UiConfirmTotal(spending, fee, fee_rate, coin, amount_unit, address_n)) # type: ignore [awaitable-return-type] -def confirm_joint_total(spending: int, total: int, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[Any]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmJointTotal(spending, total, coin, amount_unit)) +def confirm_joint_total(spending: int, total: int, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[Any]: # type: ignore [awaitable-return-type] + return (yield UiConfirmJointTotal(spending, total, coin, amount_unit)) # type: ignore [awaitable-return-type] -def confirm_feeoverthreshold(fee: int, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[Any]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmFeeOverThreshold(fee, coin, amount_unit)) +def confirm_feeoverthreshold(fee: int, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[Any]: # type: ignore [awaitable-return-type] + return (yield UiConfirmFeeOverThreshold(fee, coin, amount_unit)) # type: ignore [awaitable-return-type] -def confirm_change_count_over_threshold(change_count: int) -> Awaitable[Any]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmChangeCountOverThreshold(change_count)) +def confirm_change_count_over_threshold(change_count: int) -> Awaitable[Any]: # type: ignore [awaitable-return-type] + return (yield UiConfirmChangeCountOverThreshold(change_count)) # type: ignore [awaitable-return-type] -def confirm_unverified_external_input() -> Awaitable[Any]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmUnverifiedExternalInput()) +def confirm_unverified_external_input() -> Awaitable[Any]: # type: ignore [awaitable-return-type] + return (yield UiConfirmUnverifiedExternalInput()) # type: ignore [awaitable-return-type] -def confirm_foreign_address(address_n: list) -> Awaitable[Any]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmForeignAddress(address_n)) +def confirm_foreign_address(address_n: list) -> Awaitable[Any]: # type: ignore [awaitable-return-type] + return (yield UiConfirmForeignAddress(address_n)) # type: ignore [awaitable-return-type] -def confirm_nondefault_locktime(lock_time: int, lock_time_disabled: bool) -> Awaitable[Any]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmNonDefaultLocktime(lock_time, lock_time_disabled)) +def confirm_nondefault_locktime(lock_time: int, lock_time_disabled: bool) -> Awaitable[Any]: # type: ignore [awaitable-return-type] + return (yield UiConfirmNonDefaultLocktime(lock_time, lock_time_disabled)) # type: ignore [awaitable-return-type] -def confirm_multiple_accounts() -> Awaitable[Any]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmMultipleAccounts()) +def confirm_multiple_accounts() -> Awaitable[Any]: # type: ignore [awaitable-return-type] + return (yield UiConfirmMultipleAccounts()) # type: ignore [awaitable-return-type] -def request_tx_meta(tx_req: TxRequest, coin: CoinInfo, tx_hash: bytes | None = None) -> Awaitable[PrevTx]: # type: ignore [awaitable-is-generator] +def request_tx_meta(tx_req: TxRequest, coin: CoinInfo, tx_hash: bytes | None = None) -> Awaitable[PrevTx]: # type: ignore [awaitable-return-type] from trezor.messages import TxAckPrevMeta assert tx_req.details is not None tx_req.request_type = RequestType.TXMETA tx_req.details.tx_hash = tx_hash - ack = yield TxAckPrevMeta, tx_req + ack = yield TxAckPrevMeta, tx_req # type: ignore [awaitable-return-type] _clear_tx_request(tx_req) return _sanitize_tx_meta(ack.tx, coin) def request_tx_extra_data( tx_req: TxRequest, offset: int, size: int, tx_hash: bytes | None = None -) -> Awaitable[bytearray]: # type: ignore [awaitable-is-generator] +) -> Awaitable[bytearray]: # type: ignore [awaitable-return-type] from trezor.messages import TxAckPrevExtraData details = tx_req.details # local_cache_attribute @@ -324,12 +324,12 @@ def request_tx_extra_data( details.extra_data_offset = offset details.extra_data_len = size details.tx_hash = tx_hash - ack = yield TxAckPrevExtraData, tx_req + ack = yield TxAckPrevExtraData, tx_req # type: ignore [awaitable-return-type] _clear_tx_request(tx_req) return ack.tx.extra_data_chunk -def request_tx_input(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes | None = None) -> Awaitable[TxInput]: # type: ignore [awaitable-is-generator] +def request_tx_input(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes | None = None) -> Awaitable[TxInput]: # type: ignore [awaitable-return-type] from trezor.messages import TxAckInput assert tx_req.details is not None @@ -339,24 +339,24 @@ def request_tx_input(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes | else: tx_req.request_type = RequestType.TXINPUT tx_req.details.request_index = i - ack = yield TxAckInput, tx_req + ack = yield TxAckInput, tx_req # type: ignore [awaitable-return-type] _clear_tx_request(tx_req) return _sanitize_tx_input(ack.tx.input, coin) -def request_tx_prev_input(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes | None = None) -> Awaitable[PrevInput]: # type: ignore [awaitable-is-generator] +def request_tx_prev_input(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes | None = None) -> Awaitable[PrevInput]: # type: ignore [awaitable-return-type] from trezor.messages import TxAckPrevInput assert tx_req.details is not None tx_req.request_type = RequestType.TXINPUT tx_req.details.request_index = i tx_req.details.tx_hash = tx_hash - ack = yield TxAckPrevInput, tx_req + ack = yield TxAckPrevInput, tx_req # type: ignore [awaitable-return-type] _clear_tx_request(tx_req) return _sanitize_tx_prev_input(ack.tx.input, coin) -def request_tx_output(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes | None = None) -> Awaitable[TxOutput]: # type: ignore [awaitable-is-generator] +def request_tx_output(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes | None = None) -> Awaitable[TxOutput]: # type: ignore [awaitable-return-type] from trezor.messages import TxAckOutput assert tx_req.details is not None @@ -366,38 +366,38 @@ def request_tx_output(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes else: tx_req.request_type = RequestType.TXOUTPUT tx_req.details.request_index = i - ack = yield TxAckOutput, tx_req + ack = yield TxAckOutput, tx_req # type: ignore [awaitable-return-type] _clear_tx_request(tx_req) return _sanitize_tx_output(ack.tx.output, coin) -def request_tx_prev_output(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes | None = None) -> Awaitable[PrevOutput]: # type: ignore [awaitable-is-generator] +def request_tx_prev_output(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes | None = None) -> Awaitable[PrevOutput]: # type: ignore [awaitable-return-type] from trezor.messages import TxAckPrevOutput assert tx_req.details is not None tx_req.request_type = RequestType.TXOUTPUT tx_req.details.request_index = i tx_req.details.tx_hash = tx_hash - ack = yield TxAckPrevOutput, tx_req + ack = yield TxAckPrevOutput, tx_req # type: ignore [awaitable-return-type] _clear_tx_request(tx_req) # return sanitize_tx_prev_output(ack.tx, coin) # no sanitize is required return ack.tx.output -def request_payment_req(tx_req: TxRequest, i: int) -> Awaitable[TxAckPaymentRequest]: # type: ignore [awaitable-is-generator] +def request_payment_req(tx_req: TxRequest, i: int) -> Awaitable[TxAckPaymentRequest]: # type: ignore [awaitable-return-type] from trezor.messages import TxAckPaymentRequest assert tx_req.details is not None tx_req.request_type = RequestType.TXPAYMENTREQ tx_req.details.request_index = i - ack = yield TxAckPaymentRequest, tx_req + ack = yield TxAckPaymentRequest, tx_req # type: ignore [awaitable-return-type] _clear_tx_request(tx_req) return _sanitize_payment_req(ack) -def request_tx_finish(tx_req: TxRequest) -> Awaitable[None]: # type: ignore [awaitable-is-generator] +def request_tx_finish(tx_req: TxRequest) -> Awaitable[None]: # type: ignore [awaitable-return-type] tx_req.request_type = RequestType.TXFINISHED - yield None, tx_req + yield None, tx_req # type: ignore [awaitable-return-type] _clear_tx_request(tx_req) diff --git a/core/src/apps/cardano/addresses.py b/core/src/apps/cardano/addresses.py index 2bab218340..917172c4ea 100644 --- a/core/src/apps/cardano/addresses.py +++ b/core/src/apps/cardano/addresses.py @@ -129,7 +129,7 @@ def _validate_address_parameters_structure( script_staking_hash = parameters.script_staking_hash # local_cache_attribute CAT = CardanoAddressType # local_cache_global - fields_to_be_empty: dict[CAT, tuple[Any, ...]] = { + fields_to_be_empty: dict[CardanoAddressType, tuple[Any, ...]] = { CAT.BASE: ( certificate_pointer, script_payment_hash, diff --git a/core/src/apps/cardano/certificates.py b/core/src/apps/cardano/certificates.py index 2c116860c0..bd3a354310 100644 --- a/core/src/apps/cardano/certificates.py +++ b/core/src/apps/cardano/certificates.py @@ -70,7 +70,7 @@ def _validate_structure(certificate: messages.CardanoTxCertificate) -> None: pool_parameters = certificate.pool_parameters # local_cache_attribute CCT = CardanoCertificateType # local_cache_global - fields_to_be_empty: dict[CCT, tuple[Any, ...]] = { + fields_to_be_empty: dict[CardanoCertificateType, tuple[Any, ...]] = { CCT.STAKE_REGISTRATION: (pool, pool_parameters), CCT.STAKE_DELEGATION: (pool_parameters,), CCT.STAKE_DEREGISTRATION: (pool, pool_parameters), diff --git a/core/src/apps/cardano/helpers/hash_builder_collection.py b/core/src/apps/cardano/helpers/hash_builder_collection.py index b9344c1d59..430a7426bc 100644 --- a/core/src/apps/cardano/helpers/hash_builder_collection.py +++ b/core/src/apps/cardano/helpers/hash_builder_collection.py @@ -23,7 +23,7 @@ class HashBuilderCollection: self.size = size self.remaining = size self.hash_fn: HashContext | None = None - self.parent: "HashBuilderCollection" | None = None + self.parent: "HashBuilderCollection | None" = None self.has_unfinished_child = False def start(self, hash_fn: HashContext) -> "HashBuilderCollection": diff --git a/core/src/apps/cardano/native_script.py b/core/src/apps/cardano/native_script.py index c8e12df7f2..c17baeaefe 100644 --- a/core/src/apps/cardano/native_script.py +++ b/core/src/apps/cardano/native_script.py @@ -73,7 +73,7 @@ def _validate_native_script_structure(script: messages.CardanoNativeScript) -> N invalid_hereafter = script.invalid_hereafter # local_cache_attribute CNST = CardanoNativeScriptType # local_cache_global - fields_to_be_empty: dict[CNST, tuple[Any, ...]] = { + fields_to_be_empty: dict[CardanoNativeScriptType, tuple[Any, ...]] = { CNST.PUB_KEY: ( scripts, required_signatures_count, diff --git a/core/src/apps/common/paths.py b/core/src/apps/common/paths.py index 4fc9712263..fb3a32825b 100644 --- a/core/src/apps/common/paths.py +++ b/core/src/apps/common/paths.py @@ -9,7 +9,7 @@ if TYPE_CHECKING: from typing_extensions import Protocol - Bip32Path = Sequence[int] + Bip32Path = list[int] Slip21Path = Sequence[bytes] PathType = TypeVar("PathType", Bip32Path, Slip21Path, contravariant=True) @@ -290,7 +290,7 @@ class PathSchema: # Which in practice it is, the only non-Collection is Interval. # But we're not going to introduce an additional type requirement # for the sake of __repr__ that doesn't exist in production anyway - collection: Collection[int] = component # type: ignore [Expression of type "Container[int]" cannot be assigned to declared type "Collection[int]"] + collection: Collection[int] = component # type: ignore [Expression of type "Container[int]" is incompatible with declared type "Collection[int]"] component_str = ",".join(str(unharden(i)) for i in collection) if len(collection) > 1: component_str = "[" + component_str + "]" diff --git a/core/src/apps/common/request_pin.py b/core/src/apps/common/request_pin.py index fd5ad0d0ab..95afa1b8fb 100644 --- a/core/src/apps/common/request_pin.py +++ b/core/src/apps/common/request_pin.py @@ -118,7 +118,7 @@ async def verify_user_pin( raise RuntimeError while retry: - pin = await request_pin_on_device( # type: ignore ["request_pin_on_device" is possibly unbound] + pin = await request_pin_on_device( TR.pin__enter, config.get_pin_rem(), allow_cancel, wrong_pin=True ) if config.unlock(pin, salt): diff --git a/core/src/apps/debug/__init__.py b/core/src/apps/debug/__init__.py index 1e2917183a..8b2f18774c 100644 --- a/core/src/apps/debug/__init__.py +++ b/core/src/apps/debug/__init__.py @@ -129,7 +129,7 @@ if __debug__: async def return_layout_change() -> None: content_tokens = await get_layout_change_content() - assert DEBUG_CONTEXT is not None + assert isinstance(DEBUG_CONTEXT, context.Context) if storage.layout_watcher is LAYOUT_WATCHER_LAYOUT: await DEBUG_CONTEXT.write(DebugLinkLayout(tokens=content_tokens)) else: diff --git a/core/src/apps/solana/transaction/__init__.py b/core/src/apps/solana/transaction/__init__.py index d09b9c72be..21e2a1cde1 100644 --- a/core/src/apps/solana/transaction/__init__.py +++ b/core/src/apps/solana/transaction/__init__.py @@ -169,7 +169,7 @@ class Transaction: def _create_instructions(self) -> None: # Instructions reference accounts by index in this combined list. combined_accounts = ( - self.addresses # type: ignore [Operator "+" not supported for types "list[Address]" and "list[AddressReference]"] + self.addresses + self.address_lookup_tables_rw_addresses + self.address_lookup_tables_ro_addresses ) diff --git a/core/src/storage/device.py b/core/src/storage/device.py index cf6ba0e929..215acc39c8 100644 --- a/core/src/storage/device.py +++ b/core/src/storage/device.py @@ -132,7 +132,7 @@ def get_backup_type() -> BackupType: ): # Invalid backup type raise RuntimeError - return backup_type # type: ignore [int-into-enum] + return backup_type def is_passphrase_enabled() -> bool: @@ -304,7 +304,7 @@ def safety_check_level() -> StorageSafetyCheckLevel: if level not in (SAFETY_CHECK_LEVEL_STRICT, SAFETY_CHECK_LEVEL_PROMPT): return _DEFAULT_SAFETY_CHECK_LEVEL else: - return level # type: ignore [int-into-enum] + return level # do not use this function directly, see apps.common.safety_checks instead diff --git a/core/src/trezor/log.py b/core/src/trezor/log.py index 4f666e30ff..4c3aa65d05 100644 --- a/core/src/trezor/log.py +++ b/core/src/trezor/log.py @@ -60,11 +60,11 @@ def exception(name: str, exc: BaseException) -> None: name, _DEBUG, "ui.Result: %s", - exc.value, # type: ignore[Cannot access member "value" for type "BaseException"] + exc.value, # type: ignore[Cannot access attribute "value" for class "BaseException"] ) elif exc.__class__.__name__ == "Cancelled": _log(name, _DEBUG, "ui.Cancelled") else: _log(name, _ERROR, "exception:") # since mypy 0.770 we cannot override sys, so print_exception is unknown - sys.print_exception(exc) # type: ignore ["print_exception" is not a known member of module] + sys.print_exception(exc) # type: ignore ["print_exception" is not a known attribute of module] diff --git a/core/src/trezor/loop.py b/core/src/trezor/loop.py index d631e54ae6..54f85eddeb 100644 --- a/core/src/trezor/loop.py +++ b/core/src/trezor/loop.py @@ -295,7 +295,7 @@ class race(Syscall): # child is a layout -- type-wise, it is an Awaitable, but # implementation-wise it is an Iterable and we know that its __iter__ # will return a Generator. - child_task = child.__iter__() # type: ignore [Cannot access member "__iter__" for type "Awaitable[Unknown]";;Cannot access member "__iter__" for type "Coroutine[Unknown, Unknown, Unknown]"] + child_task = child.__iter__() # type: ignore [Cannot access attribute "__iter__" for class "Awaitable[Unknown]";;Cannot access attribute "__iter__" for class "Coroutine[Unknown, Unknown, Unknown]"] schedule(child_task, None, None, finalizer) scheduled.append(child_task) @@ -319,7 +319,7 @@ class race(Syscall): self.exit(task) schedule(self.callback, result) - def __iter__(self) -> Task: # type: ignore [awaitable-is-generator] + def __iter__(self) -> Task: try: return (yield self) except: # noqa: E722 @@ -383,20 +383,20 @@ class chan: self.putters: list[tuple[Task | None, Any]] = [] self.takers: list[Task] = [] - def put(self, value: Any) -> Awaitable[None]: # type: ignore [awaitable-is-generator] + def put(self, value: Any) -> Awaitable[None]: # type: ignore [awaitable-return-type] put = chan.Put(self, value) try: - return (yield put) + return (yield put) # type: ignore [awaitable-return-type] except: # noqa: E722 entry = (put.task, value) if entry in self.putters: self.putters.remove(entry) raise - def take(self) -> Awaitable[Any]: # type: ignore [awaitable-is-generator] + def take(self) -> Awaitable[Any]: # type: ignore [awaitable-return-type] take = chan.Take(self) try: - return (yield take) + return (yield take) # type: ignore [awaitable-return-type] except: # noqa: E722 if take.task in self.takers: self.takers.remove(take.task) @@ -493,7 +493,7 @@ class spawn(Syscall): if self.finalizer_callback is not None: self.finalizer_callback(self) - def __iter__(self) -> Task: # type: ignore [awaitable-is-generator] + def __iter__(self) -> Task: if self.finished: # exit immediately if we already have a return value if isinstance(self.return_value, BaseException): diff --git a/core/src/trezor/sdcard.py b/core/src/trezor/sdcard.py index 3a72402330..39ba567b71 100644 --- a/core/src/trezor/sdcard.py +++ b/core/src/trezor/sdcard.py @@ -2,8 +2,8 @@ try: from trezorio import fatfs, sdcard HAVE_SDCARD = True - is_present = sdcard.is_present # type: ignore [obscured-by-same-name] - capacity = sdcard.capacity # type: ignore [obscured-by-same-name] + is_present = sdcard.is_present + capacity = sdcard.capacity except Exception: HAVE_SDCARD = False @@ -27,7 +27,7 @@ if TYPE_CHECKING: class FilesystemWrapper: - _INSTANCE: "FilesystemWrapper" | None = None + _INSTANCE: "FilesystemWrapper | None" = None def __init__(self, mounted: bool) -> None: if not HAVE_SDCARD: diff --git a/core/src/trezor/ui/__init__.py b/core/src/trezor/ui/__init__.py index 109ed105b2..a8580a96cb 100644 --- a/core/src/trezor/ui/__init__.py +++ b/core/src/trezor/ui/__init__.py @@ -45,7 +45,7 @@ if __debug__: display.refresh() else: - refresh = display.refresh # type: ignore [obscured-by-same-name] + refresh = display.refresh # in both debug and production, emulator needs to draw the screen explicitly @@ -188,6 +188,6 @@ class Layout(Generic[T]): content_store.append(self.__class__.__name__) -def wait_until_layout_is_running() -> Awaitable[None]: # type: ignore [awaitable-is-generator] +def wait_until_layout_is_running() -> Awaitable[None]: # type: ignore [awaitable-return-type] while not layout_chan.takers: - yield + yield # type: ignore [awaitable-return-type] diff --git a/core/src/trezor/ui/layouts/common.py b/core/src/trezor/ui/layouts/common.py index 73a200cea3..f16dcc16e8 100644 --- a/core/src/trezor/ui/layouts/common.py +++ b/core/src/trezor/ui/layouts/common.py @@ -35,8 +35,8 @@ async def interact( br_code: ButtonRequestType = ButtonRequestType.Other, ) -> T: pages = None - if hasattr(layout, "page_count") and layout.page_count() > 1: # type: ignore [Cannot access member "page_count" for type "LayoutType"] + if hasattr(layout, "page_count") and layout.page_count() > 1: # type: ignore [Cannot access attribute "page_count" for class "LayoutType"] # We know for certain how many pages the layout will have - pages = layout.page_count() # type: ignore [Cannot access member "page_count" for type "LayoutType"] + pages = layout.page_count() # type: ignore [Cannot access attribute "page_count" for class "LayoutType"] await button_request(br_type, br_code, pages) return await context.wait(layout) diff --git a/core/src/trezor/ui/layouts/tr/__init__.py b/core/src/trezor/ui/layouts/tr/__init__.py index f99cc9487c..844f6a2860 100644 --- a/core/src/trezor/ui/layouts/tr/__init__.py +++ b/core/src/trezor/ui/layouts/tr/__init__.py @@ -221,7 +221,7 @@ class RustLayout(LayoutParentType[T]): notify_layout_change(self, event_id) - def handle_input_and_rendering(self) -> loop.Task: # type: ignore [awaitable-is-generator] + def handle_input_and_rendering(self) -> loop.Task: from trezor import workflow button = loop.wait(io.BUTTON) @@ -237,7 +237,7 @@ class RustLayout(LayoutParentType[T]): raise ui.Result(msg) self._paint() - def handle_timers(self) -> loop.Task: # type: ignore [awaitable-is-generator] + def handle_timers(self) -> loop.Task: while True: # Using `yield` instead of `await` to avoid allocations. token = yield self.timer @@ -849,7 +849,7 @@ async def _confirm_ask_pagination( ) -> None: paginated: RustLayout[trezorui2.UiResult] | None = None # TODO: make should_show_more/confirm_more accept bytes directly - if isinstance(data, bytes): + if isinstance(data, (bytes, bytearray, memoryview)): from ubinascii import hexlify data = hexlify(data).decode() @@ -939,13 +939,14 @@ def confirm_properties( from ubinascii import hexlify def handle_bytes(prop: PropertyType): - if isinstance(prop[1], bytes): - return (prop[0], hexlify(prop[1]).decode(), True) + key, value = prop + if isinstance(value, (bytes, bytearray, memoryview)): + return (key, hexlify(value).decode(), True) else: # When there is not space in the text, taking it as data # to not include hyphens - is_data = prop[1] and " " not in prop[1] - return (prop[0], prop[1], is_data) + is_data = value and " " not in value + return (key, value, is_data) return raise_if_not_confirmed( interact( @@ -1407,7 +1408,7 @@ def show_error_popup( time_ms=timeout_ms, ) ) - return layout # type: ignore [Expression of type "RustLayout[UiResult]" cannot be assigned to return type "Awaitable[None]"] + return layout # type: ignore [Expression of type "RustLayout[UiResult]" is incompatible with return type "Awaitable[None]"] def request_passphrase_on_host() -> None: diff --git a/core/src/trezor/ui/layouts/tt/__init__.py b/core/src/trezor/ui/layouts/tt/__init__.py index 919f9a9625..34b4e603ba 100644 --- a/core/src/trezor/ui/layouts/tt/__init__.py +++ b/core/src/trezor/ui/layouts/tt/__init__.py @@ -193,7 +193,7 @@ class RustLayout(LayoutParentType[T]): # Turn the brightness on again. ui.backlight_fade(self.BACKLIGHT_LEVEL) - def handle_input_and_rendering(self) -> loop.Task: # type: ignore [awaitable-is-generator] + def handle_input_and_rendering(self) -> loop.Task: from trezor import workflow touch = loop.wait(io.TOUCH) @@ -209,7 +209,7 @@ class RustLayout(LayoutParentType[T]): raise ui.Result(msg) self._paint() - def handle_timers(self) -> loop.Task: # type: ignore [awaitable-is-generator] + def handle_timers(self) -> loop.Task: while True: # Using `yield` instead of `await` to avoid allocations. token = yield self.timer @@ -691,7 +691,7 @@ async def should_show_payment_request_details( async def should_show_more( title: str, - para: Iterable[tuple[int, str]], + para: Iterable[tuple[int, str | bytes]], button_text: str | None = None, br_type: str = "should_show_more", br_code: ButtonRequestType = BR_TYPE_OTHER, @@ -1397,7 +1397,7 @@ def show_error_popup( allow_cancel=False, ) ) - return layout # type: ignore [Expression of type "RustLayout[UiResult]" cannot be assigned to return type "Awaitable[None]"] + return layout # type: ignore [Expression of type "RustLayout[UiResult]" is incompatible with return type "Awaitable[None]"] def request_passphrase_on_host() -> None: diff --git a/core/src/trezor/utils.py b/core/src/trezor/utils.py index 2ee5b05f96..e3ca5be872 100644 --- a/core/src/trezor/utils.py +++ b/core/src/trezor/utils.py @@ -302,14 +302,14 @@ class BufferReader: return byte -def obj_eq(self: Any, __o: Any) -> bool: +def obj_eq(__self: Any, __o: Any) -> bool: """ Compares object contents. """ - if self.__class__ is not __o.__class__: + if __self.__class__ is not __o.__class__: return False - assert not hasattr(self, "__slots__") - return self.__dict__ == __o.__dict__ + assert not hasattr(__self, "__slots__") + return __self.__dict__ == __o.__dict__ def obj_repr(self: Any) -> str: diff --git a/tools/pyright_tool.py b/tools/pyright_tool.py index 8af0beac0a..535fecb248 100755 --- a/tools/pyright_tool.py +++ b/tools/pyright_tool.py @@ -141,9 +141,9 @@ FILE_SPECIFIC_IGNORES: FileSpecificIgnores = {} # Allowing for more readable ignore of common problems, with an easy-to-understand alias ALIASES: dict[str, str] = { - "awaitable-is-generator": 'Return type of generator function must be "Generator" or "Iterable"', + "awaitable-return-type": 'Return type of generator function must be compatible with "Generator', "obscured-by-same-name": "is obscured by a declaration of the same name", - "int-into-enum": 'Expression of type "int.*" cannot be assigned to return type ".*"', + "int-into-enum": 'Expression of type "int.*" is incompatible with return type ".*"', }