1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 04:18:10 +00:00

style(core): upgrade pyright to 1.1.361

[no changelog]
This commit is contained in:
matejcik 2024-04-29 13:02:40 +02:00 committed by matejcik
parent ec8da46fe5
commit 8640b50d81
25 changed files with 106 additions and 104 deletions

View File

@ -1877,7 +1877,7 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// title: str, /// title: str,
/// button: str, /// button: str,
/// info_button: str, # unused on TR /// info_button: str, # unused on TR
/// items: Iterable[Tuple[int, str]], /// items: Iterable[Tuple[int, str | bytes]],
/// verb_cancel: str | None = None, /// verb_cancel: str | None = None,
/// ) -> LayoutObj[UiResult]: /// ) -> LayoutObj[UiResult]:
/// """Confirm given items but with third button. Always single page /// """Confirm given items but with third button. Always single page
@ -1888,7 +1888,7 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// *, /// *,
/// title: str, /// title: str,
/// button: str, /// button: str,
/// items: Iterable[tuple[int, str]], /// items: Iterable[tuple[int, str | bytes]],
/// ) -> object: /// ) -> object:
/// """Confirm long content with the possibility to go back from any page. /// """Confirm long content with the possibility to go back from any page.
/// Meant to be used with confirm_with_info.""" /// Meant to be used with confirm_with_info."""

View File

@ -1947,7 +1947,7 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// title: str, /// title: str,
/// button: str, /// button: str,
/// info_button: str, /// info_button: str,
/// items: Iterable[tuple[int, str]], /// items: Iterable[tuple[int, str | bytes]],
/// ) -> LayoutObj[UiResult]: /// ) -> LayoutObj[UiResult]:
/// """Confirm given items but with third button. Always single page /// """Confirm given items but with third button. Always single page
/// without scrolling.""" /// without scrolling."""
@ -1957,7 +1957,7 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// *, /// *,
/// title: str, /// title: str,
/// button: str, /// button: str,
/// items: Iterable[tuple[int, str]], /// items: Iterable[tuple[int, str | bytes]],
/// ) -> LayoutObj[UiResult]: /// ) -> LayoutObj[UiResult]:
/// """Confirm long content with the possibility to go back from any page. /// """Confirm long content with the possibility to go back from any page.
/// Meant to be used with confirm_with_info.""" /// Meant to be used with confirm_with_info."""

View File

@ -257,7 +257,7 @@ def confirm_with_info(
title: str, title: str,
button: str, button: str,
info_button: str, # unused on TR info_button: str, # unused on TR
items: Iterable[Tuple[int, str]], items: Iterable[Tuple[int, str | bytes]],
verb_cancel: str | None = None, verb_cancel: str | None = None,
) -> LayoutObj[UiResult]: ) -> LayoutObj[UiResult]:
"""Confirm given items but with third button. Always single page """Confirm given items but with third button. Always single page
@ -269,7 +269,7 @@ def confirm_more(
*, *,
title: str, title: str,
button: str, button: str,
items: Iterable[tuple[int, str]], items: Iterable[tuple[int, str | bytes]],
) -> object: ) -> object:
"""Confirm long content with the possibility to go back from any page. """Confirm long content with the possibility to go back from any page.
Meant to be used with confirm_with_info.""" Meant to be used with confirm_with_info."""
@ -768,7 +768,7 @@ def confirm_with_info(
title: str, title: str,
button: str, button: str,
info_button: str, info_button: str,
items: Iterable[tuple[int, str]], items: Iterable[tuple[int, str | bytes]],
) -> LayoutObj[UiResult]: ) -> LayoutObj[UiResult]:
"""Confirm given items but with third button. Always single page """Confirm given items but with third button. Always single page
without scrolling.""" without scrolling."""
@ -779,7 +779,7 @@ def confirm_more(
*, *,
title: str, title: str,
button: str, button: str,
items: Iterable[tuple[int, str]], items: Iterable[tuple[int, str | bytes]],
) -> LayoutObj[UiResult]: ) -> LayoutObj[UiResult]:
"""Confirm long content with the possibility to go back from any page. """Confirm long content with the possibility to go back from any page.
Meant to be used with confirm_with_info.""" Meant to be used with confirm_with_info."""

View File

@ -418,7 +418,7 @@ def get_pinlocked_handler(
if msg_type in workflow.ALLOW_WHILE_LOCKED: if msg_type in workflow.ALLOW_WHILE_LOCKED:
return orig_handler return orig_handler
async def wrapper(msg: wire.Msg) -> protobuf.MessageType: async def wrapper(msg: protobuf.MessageType) -> protobuf.MessageType:
await unlock_device() await unlock_device()
return await orig_handler(msg) return await orig_handler(msg)
@ -442,7 +442,7 @@ def boot() -> None:
MT = MessageType # local_cache_global MT = MessageType # local_cache_global
# Register workflow handlers # Register workflow handlers
for msg_type, handler in ( for msg_type, handler in [
(MT.Initialize, handle_Initialize), (MT.Initialize, handle_Initialize),
(MT.GetFeatures, handle_GetFeatures), (MT.GetFeatures, handle_GetFeatures),
(MT.Cancel, handle_Cancel), (MT.Cancel, handle_Cancel),
@ -453,8 +453,8 @@ def boot() -> None:
(MT.UnlockPath, handle_UnlockPath), (MT.UnlockPath, handle_UnlockPath),
(MT.CancelAuthorization, handle_CancelAuthorization), (MT.CancelAuthorization, handle_CancelAuthorization),
(MT.SetBusy, handle_SetBusy), (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() reload_settings_from_storage()
if config.is_unlocked(): if config.is_unlocked():

View File

@ -46,7 +46,8 @@ class SigHashType(IntEnum):
@classmethod @classmethod
def from_int(cls, sighash_type: int) -> "SigHashType": 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: if val == sighash_type:
return val return val
raise ValueError("Unsupported sighash type.") raise ValueError("Unsupported sighash type.")

View File

@ -316,7 +316,7 @@ def _get_unlock_schemas(
def with_keychain(func: HandlerWithCoinInfo[MsgOut]) -> Handler[MsgIn, MsgOut]: def with_keychain(func: HandlerWithCoinInfo[MsgOut]) -> Handler[MsgIn, MsgOut]:
async def wrapper( async def wrapper(
msg: MsgIn, msg: BitcoinMessage,
auth_msg: MessageType | None = None, auth_msg: MessageType | None = None,
) -> MsgOut: ) -> MsgOut:
coin = _get_coin_by_name(msg.coin_name) coin = _get_coin_by_name(msg.coin_name)

View File

@ -241,80 +241,80 @@ class UiConfirmMultipleAccounts(UiConfirm):
return layout.confirm_multiple_accounts() 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] 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)) 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] 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)) 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] 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)) 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] def confirm_replacement(description: str, txid: bytes) -> Awaitable[Any]: # type: ignore [awaitable-return-type]
return (yield UiConfirmReplacement(description, txid)) 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] 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)) 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 ( return (
yield UiConfirmModifyFee( yield UiConfirmModifyFee( # type: ignore [awaitable-return-type]
title, user_fee_change, total_fee_new, fee_rate, coin, amount_unit 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] 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)) 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] 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)) 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] def confirm_feeoverthreshold(fee: int, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[Any]: # type: ignore [awaitable-return-type]
return (yield UiConfirmFeeOverThreshold(fee, coin, amount_unit)) 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] def confirm_change_count_over_threshold(change_count: int) -> Awaitable[Any]: # type: ignore [awaitable-return-type]
return (yield UiConfirmChangeCountOverThreshold(change_count)) return (yield UiConfirmChangeCountOverThreshold(change_count)) # type: ignore [awaitable-return-type]
def confirm_unverified_external_input() -> Awaitable[Any]: # type: ignore [awaitable-is-generator] def confirm_unverified_external_input() -> Awaitable[Any]: # type: ignore [awaitable-return-type]
return (yield UiConfirmUnverifiedExternalInput()) return (yield UiConfirmUnverifiedExternalInput()) # type: ignore [awaitable-return-type]
def confirm_foreign_address(address_n: list) -> Awaitable[Any]: # type: ignore [awaitable-is-generator] def confirm_foreign_address(address_n: list) -> Awaitable[Any]: # type: ignore [awaitable-return-type]
return (yield UiConfirmForeignAddress(address_n)) 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] 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)) return (yield UiConfirmNonDefaultLocktime(lock_time, lock_time_disabled)) # type: ignore [awaitable-return-type]
def confirm_multiple_accounts() -> Awaitable[Any]: # type: ignore [awaitable-is-generator] def confirm_multiple_accounts() -> Awaitable[Any]: # type: ignore [awaitable-return-type]
return (yield UiConfirmMultipleAccounts()) 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 from trezor.messages import TxAckPrevMeta
assert tx_req.details is not None assert tx_req.details is not None
tx_req.request_type = RequestType.TXMETA tx_req.request_type = RequestType.TXMETA
tx_req.details.tx_hash = tx_hash 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) _clear_tx_request(tx_req)
return _sanitize_tx_meta(ack.tx, coin) return _sanitize_tx_meta(ack.tx, coin)
def request_tx_extra_data( def request_tx_extra_data(
tx_req: TxRequest, offset: int, size: int, tx_hash: bytes | None = None 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 from trezor.messages import TxAckPrevExtraData
details = tx_req.details # local_cache_attribute details = tx_req.details # local_cache_attribute
@ -324,12 +324,12 @@ def request_tx_extra_data(
details.extra_data_offset = offset details.extra_data_offset = offset
details.extra_data_len = size details.extra_data_len = size
details.tx_hash = tx_hash 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) _clear_tx_request(tx_req)
return ack.tx.extra_data_chunk 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 from trezor.messages import TxAckInput
assert tx_req.details is not None 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: else:
tx_req.request_type = RequestType.TXINPUT tx_req.request_type = RequestType.TXINPUT
tx_req.details.request_index = i 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) _clear_tx_request(tx_req)
return _sanitize_tx_input(ack.tx.input, coin) 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 from trezor.messages import TxAckPrevInput
assert tx_req.details is not None assert tx_req.details is not None
tx_req.request_type = RequestType.TXINPUT tx_req.request_type = RequestType.TXINPUT
tx_req.details.request_index = i tx_req.details.request_index = i
tx_req.details.tx_hash = tx_hash 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) _clear_tx_request(tx_req)
return _sanitize_tx_prev_input(ack.tx.input, coin) 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 from trezor.messages import TxAckOutput
assert tx_req.details is not None 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: else:
tx_req.request_type = RequestType.TXOUTPUT tx_req.request_type = RequestType.TXOUTPUT
tx_req.details.request_index = i 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) _clear_tx_request(tx_req)
return _sanitize_tx_output(ack.tx.output, coin) 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 from trezor.messages import TxAckPrevOutput
assert tx_req.details is not None assert tx_req.details is not None
tx_req.request_type = RequestType.TXOUTPUT tx_req.request_type = RequestType.TXOUTPUT
tx_req.details.request_index = i tx_req.details.request_index = i
tx_req.details.tx_hash = tx_hash 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) _clear_tx_request(tx_req)
# return sanitize_tx_prev_output(ack.tx, coin) # no sanitize is required # return sanitize_tx_prev_output(ack.tx, coin) # no sanitize is required
return ack.tx.output 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 from trezor.messages import TxAckPaymentRequest
assert tx_req.details is not None assert tx_req.details is not None
tx_req.request_type = RequestType.TXPAYMENTREQ tx_req.request_type = RequestType.TXPAYMENTREQ
tx_req.details.request_index = i 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) _clear_tx_request(tx_req)
return _sanitize_payment_req(ack) 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 tx_req.request_type = RequestType.TXFINISHED
yield None, tx_req yield None, tx_req # type: ignore [awaitable-return-type]
_clear_tx_request(tx_req) _clear_tx_request(tx_req)

View File

@ -129,7 +129,7 @@ def _validate_address_parameters_structure(
script_staking_hash = parameters.script_staking_hash # local_cache_attribute script_staking_hash = parameters.script_staking_hash # local_cache_attribute
CAT = CardanoAddressType # local_cache_global CAT = CardanoAddressType # local_cache_global
fields_to_be_empty: dict[CAT, tuple[Any, ...]] = { fields_to_be_empty: dict[CardanoAddressType, tuple[Any, ...]] = {
CAT.BASE: ( CAT.BASE: (
certificate_pointer, certificate_pointer,
script_payment_hash, script_payment_hash,

View File

@ -70,7 +70,7 @@ def _validate_structure(certificate: messages.CardanoTxCertificate) -> None:
pool_parameters = certificate.pool_parameters # local_cache_attribute pool_parameters = certificate.pool_parameters # local_cache_attribute
CCT = CardanoCertificateType # local_cache_global 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_REGISTRATION: (pool, pool_parameters),
CCT.STAKE_DELEGATION: (pool_parameters,), CCT.STAKE_DELEGATION: (pool_parameters,),
CCT.STAKE_DEREGISTRATION: (pool, pool_parameters), CCT.STAKE_DEREGISTRATION: (pool, pool_parameters),

View File

@ -23,7 +23,7 @@ class HashBuilderCollection:
self.size = size self.size = size
self.remaining = size self.remaining = size
self.hash_fn: HashContext | None = None self.hash_fn: HashContext | None = None
self.parent: "HashBuilderCollection" | None = None self.parent: "HashBuilderCollection | None" = None
self.has_unfinished_child = False self.has_unfinished_child = False
def start(self, hash_fn: HashContext) -> "HashBuilderCollection": def start(self, hash_fn: HashContext) -> "HashBuilderCollection":

View File

@ -73,7 +73,7 @@ def _validate_native_script_structure(script: messages.CardanoNativeScript) -> N
invalid_hereafter = script.invalid_hereafter # local_cache_attribute invalid_hereafter = script.invalid_hereafter # local_cache_attribute
CNST = CardanoNativeScriptType # local_cache_global CNST = CardanoNativeScriptType # local_cache_global
fields_to_be_empty: dict[CNST, tuple[Any, ...]] = { fields_to_be_empty: dict[CardanoNativeScriptType, tuple[Any, ...]] = {
CNST.PUB_KEY: ( CNST.PUB_KEY: (
scripts, scripts,
required_signatures_count, required_signatures_count,

View File

@ -9,7 +9,7 @@ if TYPE_CHECKING:
from typing_extensions import Protocol from typing_extensions import Protocol
Bip32Path = Sequence[int] Bip32Path = list[int]
Slip21Path = Sequence[bytes] Slip21Path = Sequence[bytes]
PathType = TypeVar("PathType", Bip32Path, Slip21Path, contravariant=True) PathType = TypeVar("PathType", Bip32Path, Slip21Path, contravariant=True)
@ -290,7 +290,7 @@ class PathSchema:
# Which in practice it is, the only non-Collection is Interval. # Which in practice it is, the only non-Collection is Interval.
# But we're not going to introduce an additional type requirement # But we're not going to introduce an additional type requirement
# for the sake of __repr__ that doesn't exist in production anyway # 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) component_str = ",".join(str(unharden(i)) for i in collection)
if len(collection) > 1: if len(collection) > 1:
component_str = "[" + component_str + "]" component_str = "[" + component_str + "]"

View File

@ -118,7 +118,7 @@ async def verify_user_pin(
raise RuntimeError raise RuntimeError
while retry: 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 TR.pin__enter, config.get_pin_rem(), allow_cancel, wrong_pin=True
) )
if config.unlock(pin, salt): if config.unlock(pin, salt):

View File

@ -129,7 +129,7 @@ if __debug__:
async def return_layout_change() -> None: async def return_layout_change() -> None:
content_tokens = await get_layout_change_content() 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: if storage.layout_watcher is LAYOUT_WATCHER_LAYOUT:
await DEBUG_CONTEXT.write(DebugLinkLayout(tokens=content_tokens)) await DEBUG_CONTEXT.write(DebugLinkLayout(tokens=content_tokens))
else: else:

View File

@ -169,7 +169,7 @@ class Transaction:
def _create_instructions(self) -> None: def _create_instructions(self) -> None:
# Instructions reference accounts by index in this combined list. # Instructions reference accounts by index in this combined list.
combined_accounts = ( 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_rw_addresses
+ self.address_lookup_tables_ro_addresses + self.address_lookup_tables_ro_addresses
) )

View File

@ -132,7 +132,7 @@ def get_backup_type() -> BackupType:
): ):
# Invalid backup type # Invalid backup type
raise RuntimeError raise RuntimeError
return backup_type # type: ignore [int-into-enum] return backup_type
def is_passphrase_enabled() -> bool: 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): if level not in (SAFETY_CHECK_LEVEL_STRICT, SAFETY_CHECK_LEVEL_PROMPT):
return _DEFAULT_SAFETY_CHECK_LEVEL return _DEFAULT_SAFETY_CHECK_LEVEL
else: else:
return level # type: ignore [int-into-enum] return level
# do not use this function directly, see apps.common.safety_checks instead # do not use this function directly, see apps.common.safety_checks instead

View File

@ -60,11 +60,11 @@ def exception(name: str, exc: BaseException) -> None:
name, name,
_DEBUG, _DEBUG,
"ui.Result: %s", "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": elif exc.__class__.__name__ == "Cancelled":
_log(name, _DEBUG, "ui.Cancelled") _log(name, _DEBUG, "ui.Cancelled")
else: else:
_log(name, _ERROR, "exception:") _log(name, _ERROR, "exception:")
# since mypy 0.770 we cannot override sys, so print_exception is unknown # 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]

View File

@ -295,7 +295,7 @@ class race(Syscall):
# child is a layout -- type-wise, it is an Awaitable, but # child is a layout -- type-wise, it is an Awaitable, but
# implementation-wise it is an Iterable and we know that its __iter__ # implementation-wise it is an Iterable and we know that its __iter__
# will return a Generator. # 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) schedule(child_task, None, None, finalizer)
scheduled.append(child_task) scheduled.append(child_task)
@ -319,7 +319,7 @@ class race(Syscall):
self.exit(task) self.exit(task)
schedule(self.callback, result) schedule(self.callback, result)
def __iter__(self) -> Task: # type: ignore [awaitable-is-generator] def __iter__(self) -> Task:
try: try:
return (yield self) return (yield self)
except: # noqa: E722 except: # noqa: E722
@ -383,20 +383,20 @@ class chan:
self.putters: list[tuple[Task | None, Any]] = [] self.putters: list[tuple[Task | None, Any]] = []
self.takers: list[Task] = [] 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) put = chan.Put(self, value)
try: try:
return (yield put) return (yield put) # type: ignore [awaitable-return-type]
except: # noqa: E722 except: # noqa: E722
entry = (put.task, value) entry = (put.task, value)
if entry in self.putters: if entry in self.putters:
self.putters.remove(entry) self.putters.remove(entry)
raise 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) take = chan.Take(self)
try: try:
return (yield take) return (yield take) # type: ignore [awaitable-return-type]
except: # noqa: E722 except: # noqa: E722
if take.task in self.takers: if take.task in self.takers:
self.takers.remove(take.task) self.takers.remove(take.task)
@ -493,7 +493,7 @@ class spawn(Syscall):
if self.finalizer_callback is not None: if self.finalizer_callback is not None:
self.finalizer_callback(self) self.finalizer_callback(self)
def __iter__(self) -> Task: # type: ignore [awaitable-is-generator] def __iter__(self) -> Task:
if self.finished: if self.finished:
# exit immediately if we already have a return value # exit immediately if we already have a return value
if isinstance(self.return_value, BaseException): if isinstance(self.return_value, BaseException):

View File

@ -2,8 +2,8 @@ try:
from trezorio import fatfs, sdcard from trezorio import fatfs, sdcard
HAVE_SDCARD = True HAVE_SDCARD = True
is_present = sdcard.is_present # type: ignore [obscured-by-same-name] is_present = sdcard.is_present
capacity = sdcard.capacity # type: ignore [obscured-by-same-name] capacity = sdcard.capacity
except Exception: except Exception:
HAVE_SDCARD = False HAVE_SDCARD = False
@ -27,7 +27,7 @@ if TYPE_CHECKING:
class FilesystemWrapper: class FilesystemWrapper:
_INSTANCE: "FilesystemWrapper" | None = None _INSTANCE: "FilesystemWrapper | None" = None
def __init__(self, mounted: bool) -> None: def __init__(self, mounted: bool) -> None:
if not HAVE_SDCARD: if not HAVE_SDCARD:

View File

@ -45,7 +45,7 @@ if __debug__:
display.refresh() display.refresh()
else: 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 # 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__) 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: while not layout_chan.takers:
yield yield # type: ignore [awaitable-return-type]

View File

@ -35,8 +35,8 @@ async def interact(
br_code: ButtonRequestType = ButtonRequestType.Other, br_code: ButtonRequestType = ButtonRequestType.Other,
) -> T: ) -> T:
pages = None 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 # 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) await button_request(br_type, br_code, pages)
return await context.wait(layout) return await context.wait(layout)

View File

@ -221,7 +221,7 @@ class RustLayout(LayoutParentType[T]):
notify_layout_change(self, event_id) 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 from trezor import workflow
button = loop.wait(io.BUTTON) button = loop.wait(io.BUTTON)
@ -237,7 +237,7 @@ class RustLayout(LayoutParentType[T]):
raise ui.Result(msg) raise ui.Result(msg)
self._paint() self._paint()
def handle_timers(self) -> loop.Task: # type: ignore [awaitable-is-generator] def handle_timers(self) -> loop.Task:
while True: while True:
# Using `yield` instead of `await` to avoid allocations. # Using `yield` instead of `await` to avoid allocations.
token = yield self.timer token = yield self.timer
@ -849,7 +849,7 @@ async def _confirm_ask_pagination(
) -> None: ) -> None:
paginated: RustLayout[trezorui2.UiResult] | None = None paginated: RustLayout[trezorui2.UiResult] | None = None
# TODO: make should_show_more/confirm_more accept bytes directly # TODO: make should_show_more/confirm_more accept bytes directly
if isinstance(data, bytes): if isinstance(data, (bytes, bytearray, memoryview)):
from ubinascii import hexlify from ubinascii import hexlify
data = hexlify(data).decode() data = hexlify(data).decode()
@ -939,13 +939,14 @@ def confirm_properties(
from ubinascii import hexlify from ubinascii import hexlify
def handle_bytes(prop: PropertyType): def handle_bytes(prop: PropertyType):
if isinstance(prop[1], bytes): key, value = prop
return (prop[0], hexlify(prop[1]).decode(), True) if isinstance(value, (bytes, bytearray, memoryview)):
return (key, hexlify(value).decode(), True)
else: else:
# When there is not space in the text, taking it as data # When there is not space in the text, taking it as data
# to not include hyphens # to not include hyphens
is_data = prop[1] and " " not in prop[1] is_data = value and " " not in value
return (prop[0], prop[1], is_data) return (key, value, is_data)
return raise_if_not_confirmed( return raise_if_not_confirmed(
interact( interact(
@ -1407,7 +1408,7 @@ def show_error_popup(
time_ms=timeout_ms, 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: def request_passphrase_on_host() -> None:

View File

@ -193,7 +193,7 @@ class RustLayout(LayoutParentType[T]):
# Turn the brightness on again. # Turn the brightness on again.
ui.backlight_fade(self.BACKLIGHT_LEVEL) 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 from trezor import workflow
touch = loop.wait(io.TOUCH) touch = loop.wait(io.TOUCH)
@ -209,7 +209,7 @@ class RustLayout(LayoutParentType[T]):
raise ui.Result(msg) raise ui.Result(msg)
self._paint() self._paint()
def handle_timers(self) -> loop.Task: # type: ignore [awaitable-is-generator] def handle_timers(self) -> loop.Task:
while True: while True:
# Using `yield` instead of `await` to avoid allocations. # Using `yield` instead of `await` to avoid allocations.
token = yield self.timer token = yield self.timer
@ -691,7 +691,7 @@ async def should_show_payment_request_details(
async def should_show_more( async def should_show_more(
title: str, title: str,
para: Iterable[tuple[int, str]], para: Iterable[tuple[int, str | bytes]],
button_text: str | None = None, button_text: str | None = None,
br_type: str = "should_show_more", br_type: str = "should_show_more",
br_code: ButtonRequestType = BR_TYPE_OTHER, br_code: ButtonRequestType = BR_TYPE_OTHER,
@ -1397,7 +1397,7 @@ def show_error_popup(
allow_cancel=False, 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: def request_passphrase_on_host() -> None:

View File

@ -302,14 +302,14 @@ class BufferReader:
return byte return byte
def obj_eq(self: Any, __o: Any) -> bool: def obj_eq(__self: Any, __o: Any) -> bool:
""" """
Compares object contents. Compares object contents.
""" """
if self.__class__ is not __o.__class__: if __self.__class__ is not __o.__class__:
return False return False
assert not hasattr(self, "__slots__") assert not hasattr(__self, "__slots__")
return self.__dict__ == __o.__dict__ return __self.__dict__ == __o.__dict__
def obj_repr(self: Any) -> str: def obj_repr(self: Any) -> str:

View File

@ -141,9 +141,9 @@ FILE_SPECIFIC_IGNORES: FileSpecificIgnores = {}
# Allowing for more readable ignore of common problems, with an easy-to-understand alias # Allowing for more readable ignore of common problems, with an easy-to-understand alias
ALIASES: dict[str, str] = { 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", "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 ".*"',
} }