chore(core): enforce PEP 585 style [UP035]
What changed, and why it matters
This is a large but purely cosmetic code cleanup in the Trezor firmware repository. It replaces old-style Python type-hint imports (such as typing.Sequence) with their modern equivalents (collections.abc.Sequence) to follow the PEP 585 style guide. No program logic, security checks, cryptography, or user-facing behavior was changed. The commit explicitly says '[no changelog]' and labels itself as a 'chore'.
No action required. This is a routine style/refactoring commit with no security relevance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit applies PEP 585/UP035 modernization across 109 files in core/src and tooling scripts. Changes are limited to import statements and TYPE_CHECKING blocks: moving abstract base classes (Awaitable, Callable, Collection, Container, Coroutine, Generator, Iterable, Iterator, Sequence) from typing to collections.abc, and wrapping some runtime imports inside if TYPE_CHECKING guards. There are no functional code changes, no changes to cryptographic operations, wire protocols, authorization, storage, or UI flows. One minor side effect is that some imports are now deferred under TYPE_CHECKING, which can reduce runtime import overhead but does not alter behavior.
Changed components
core/src/apps/* (type-only import cleanup)core/src/storage/* (type-only import cleanup)core/src/trezor/* (type-only import cleanup)core/tests/* (type-only import cleanup)core/tools/* (type-only import cleanup)Inspect captured patch +206 / −122
### core/src/apps/benchmark/cipher_benchmark.py
@@ -1,10 +1,11 @@
-from typing import TYPE_CHECKING, Callable
+from typing import TYPE_CHECKING
from trezor.messages import BenchmarkResult
from .common import format_float, maximum_used_memory_in_bytes, random_bytes
if TYPE_CHECKING:
+ from collections.abc import Callable
from typing import Protocol
class CipherCtxDecrypt(Protocol):
### core/src/apps/benchmark/hash_benchmark.py
@@ -1,10 +1,11 @@
-from typing import TYPE_CHECKING, Callable
+from typing import TYPE_CHECKING
from trezor.messages import BenchmarkResult
from .common import format_float, maximum_used_memory_in_bytes, random_bytes
if TYPE_CHECKING:
+ from collections.abc import Callable
from typing import Protocol
class HashCtx(Protocol):
### core/src/apps/bitcoin/addresses.py
@@ -14,7 +14,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Sequence
+ from collections.abc import Sequence
from trezor.crypto import bip32
from trezor.messages import MultisigRedeemScriptType
### core/src/apps/bitcoin/keychain.py
@@ -10,7 +10,8 @@
from .common import BIP32_WALLET_DEPTH, BITCOIN_NAMES
if TYPE_CHECKING:
- from typing import Awaitable, Callable, Iterable, TypeVar
+ from collections.abc import Awaitable, Callable, Iterable
+ from typing import TypeVar
from trezor.messages import (
GetAddress,
### core/src/apps/bitcoin/multisig.py
@@ -5,7 +5,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Sequence
+ from collections.abc import Sequence
from trezor.messages import HDNodeType, MultisigRedeemScriptType
### core/src/apps/bitcoin/scripts.py
@@ -23,7 +23,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Sequence
+ from collections.abc import Sequence
from trezor.messages import MultisigRedeemScriptType, TxInput
### core/src/apps/bitcoin/sign_tx/bitcoin.py
@@ -21,7 +21,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Sequence
+ from collections.abc import Sequence
from trezor.crypto import bip32
from trezor.messages import PrevInput, PrevOutput, PrevTx, SignTx, TxInput, TxOutput
### core/src/apps/bitcoin/sign_tx/bitcoinlike.py
@@ -5,7 +5,7 @@
from .bitcoin import Bitcoin
if TYPE_CHECKING:
- from typing import Sequence
+ from collections.abc import Sequence
from trezor.messages import PrevTx, SignTx, TxInput
### core/src/apps/bitcoin/sign_tx/decred.py
@@ -27,7 +27,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Sequence
+ from collections.abc import Sequence
from trezor.crypto import bip32
from trezor.messages import PrevInput, PrevOutput, PrevTx, SignTx, TxInput, TxOutput
### core/src/apps/bitcoin/sign_tx/helpers.py
@@ -19,7 +19,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Any, Awaitable
+ from collections.abc import Awaitable
+ from typing import Any
from trezor.enums import AmountUnit
from trezor.messages import (
### core/src/apps/bitcoin/sign_tx/sig_hasher.py
@@ -12,7 +12,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Protocol, Sequence
+ from collections.abc import Sequence
+ from typing import Protocol
from trezor.messages import PrevTx, SignTx, TxInput, TxOutput
### core/src/apps/bitcoin/sign_tx/zcash_v4.py
@@ -10,7 +10,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Sequence
+ from collections.abc import Sequence
from trezor.messages import PrevTx, SignTx, TxInput, TxOutput
### core/src/apps/bitcoin/verification.py
@@ -4,7 +4,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Sequence
+ from collections.abc import Sequence
from apps.common.coininfo import CoinInfo
### core/src/apps/cardano/layout.py
@@ -27,7 +27,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Callable, Iterable, Literal
+ from collections.abc import Callable, Iterable
+ from typing import Literal
from trezor import messages
from trezor.enums import CardanoNativeScriptHashDisplayFormat
### core/src/apps/cardano/seed.py
@@ -15,7 +15,8 @@
from .helpers.paths import BYRON_ROOT, MINTING_ROOT, MULTISIG_ROOT, SHELLEY_ROOT
if TYPE_CHECKING:
- from typing import Awaitable, Callable, TypeVar
+ from collections.abc import Awaitable, Callable
+ from typing import TypeVar
from trezor import messages
from trezor.crypto import bip32
@@ -37,7 +38,7 @@
MsgIn = TypeVar("MsgIn", bound=CardanoMessages)
HandlerWithKeychain = Callable[
- [MsgIn, "Keychain", "Slip21Keychain"], Awaitable[MsgOut]
+ [MsgIn, "Keychain", Slip21Keychain], Awaitable[MsgOut]
]
### core/src/apps/cardano/sign_tx/signer.py
@@ -27,8 +27,9 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
+ from collections.abc import Awaitable
from enum import IntEnum
- from typing import Any, Awaitable
+ from typing import Any
from trezor.enums import CardanoAddressType
### core/src/apps/common/authorization.py
@@ -1,4 +1,4 @@
-from typing import Iterable
+from typing import TYPE_CHECKING
from storage.cache_common import (
APP_COMMON_AUTHORIZATION_DATA,
@@ -8,6 +8,9 @@
from trezor.enums import MessageType
from trezor.wire import context
+if TYPE_CHECKING:
+ from collections.abc import Iterable
+
WIRE_TYPES: dict[int, tuple[int, ...]] = {
MessageType.AuthorizeCoinJoin: (MessageType.SignTx, MessageType.GetOwnershipProof),
}
### core/src/apps/common/cache.py
@@ -3,7 +3,8 @@
from trezor.wire import context
if TYPE_CHECKING:
- from typing import Awaitable, Callable, ParamSpec
+ from collections.abc import Awaitable, Callable
+ from typing import ParamSpec
P = ParamSpec("P")
ByteFunc = Callable[P, bytes]
### core/src/apps/common/cbor.py
@@ -8,7 +8,8 @@
from trezor import log
if TYPE_CHECKING:
- from typing import Any, Generic, Iterator, TypeVar
+ from collections.abc import Iterator
+ from typing import Any, Generic, TypeVar
from trezor.utils import BufferReader
### core/src/apps/common/chunked.py
@@ -7,7 +7,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Callable
+ from collections.abc import Callable
_CHUNK_SIZE = const(1024)
### core/src/apps/common/keychain.py
@@ -6,7 +6,8 @@
from . import paths, safety_checks
if TYPE_CHECKING:
- from typing import Any, Awaitable, Callable, Iterable, TypeVar
+ from collections.abc import Awaitable, Callable, Iterable
+ from typing import Any, TypeVar
from trezor.protobuf import MessageType
from typing_extensions import Protocol
### core/src/apps/common/lock_manager.py
@@ -15,7 +15,8 @@
import trezorble as ble
if TYPE_CHECKING:
- from typing import Awaitable, Callable, ParamSpec, TypeVar
+ from collections.abc import Awaitable, Callable
+ from typing import ParamSpec, TypeVar
from trezor import protobuf
from trezor.wire import Handler, Msg
### core/src/apps/common/paths.py
@@ -6,7 +6,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Any, Callable, Collection, Container, Iterable, Sequence, TypeVar
+ from collections.abc import Callable, Collection, Container, Iterable, Sequence
+ from typing import Any, TypeVar
from typing_extensions import Protocol
### core/src/apps/debug/__init__.py
@@ -17,7 +17,8 @@
from trezor.messages import Success
if TYPE_CHECKING:
- from typing import Any, Awaitable, Callable, NoReturn
+ from collections.abc import Awaitable, Callable
+ from typing import Any, NoReturn
from trezor.enums import DebugButton, DebugPhysicalButton, DebugSwipeDirection
from trezor.messages import (
### core/src/apps/debug/n1w1_mock.py
@@ -6,7 +6,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Any, Iterator
+ from collections.abc import Iterator
+ from typing import Any
from trezor.wire.context import Context
from typing_extensions import Self
### core/src/apps/eos/actions/layout.py
@@ -7,7 +7,7 @@
from ..helpers import eos_asset_to_string, eos_name_to_string
if TYPE_CHECKING:
- from typing import Iterable
+ from collections.abc import Iterable
from trezor.messages import (
EosActionBuyRam,
### core/src/apps/ethereum/clear_signing.py
@@ -14,7 +14,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Callable, Iterable, Sequence
+ from collections.abc import Callable, Iterable, Sequence
from trezor.messages import (
EthereumABIValueInfo,
### core/src/apps/ethereum/clear_signing_definitions.py
@@ -1,4 +1,4 @@
-from typing import Generator
+from typing import TYPE_CHECKING
from .clear_signing import (
AddressNameFormatter,
@@ -11,6 +11,9 @@
parse_uint256,
)
+if TYPE_CHECKING:
+ from collections.abc import Generator
+
# https://github.com/ethereum/clear-signing-erc7730-registry/blob/master/ercs/calldata-erc20-tokens.json#L27
APPROVE_DISPLAY_FORMAT = DisplayFormat(
### core/src/apps/ethereum/helpers.py
@@ -6,7 +6,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Awaitable, Callable, Sequence
+ from collections.abc import Awaitable, Callable, Sequence
from trezor.messages import EthereumFieldType, EthereumTokenInfo
from trezor.ui.layouts import StrPropertyType
### core/src/apps/ethereum/keychain.py
@@ -8,7 +8,8 @@
from . import CURVE, definitions, networks
if TYPE_CHECKING:
- from typing import Any, Awaitable, Callable, Iterable, TypeVar
+ from collections.abc import Awaitable, Callable, Iterable
+ from typing import Any, TypeVar
from trezor.messages import (
EthereumGetAddress,
### core/src/apps/ethereum/layout.py
@@ -20,7 +20,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Awaitable, Iterable, Sequence
+ from collections.abc import Awaitable, Iterable, Sequence
from trezor.messages import (
EthereumFieldType,
### core/src/apps/ethereum/networks.py
@@ -11,7 +11,7 @@
from trezor.messages import EthereumNetworkInfo
if TYPE_CHECKING:
- from typing import Iterator
+ from collections.abc import Iterator
# Removing the necessity to construct object to save space
# fmt: off
### core/src/apps/ethereum/networks.py.mako
@@ -11,7 +11,7 @@ from trezor import utils
from trezor.messages import EthereumNetworkInfo
if TYPE_CHECKING:
- from typing import Iterator
+ from collections.abc import Iterator
# Removing the necessity to construct object to save space
# fmt: off
### core/src/apps/ethereum/sc_constants.py
@@ -3,7 +3,10 @@
# do not edit manually!
# fmt: off
-from typing import Iterator
+from typing import TYPE_CHECKING
+
+if TYPE_CHECKING:
+ from collections.abc import Iterator
def lookup_known_address(chain_id: int, address: bytes) -> str | None:
### core/src/apps/ethereum/sc_constants.py.mako
@@ -3,7 +3,10 @@
# do not edit manually!
# fmt: off
-from typing import Iterator
+from typing import TYPE_CHECKING
+
+if TYPE_CHECKING:
+ from collections.abc import Iterator
<%
def fmt_addr(addr_hex: str) -> str:
data = "".join(f'\\x{b:02x}' for b in bytes.fromhex(addr_hex))
### core/src/apps/ethereum/sign_tx.py
@@ -11,7 +11,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Sequence
+ from collections.abc import Sequence
from trezor.messages import EthereumSignTx
from trezor.ui.layouts import StrPropertyType
### core/src/apps/ethereum/sign_typed_data.py
@@ -1,4 +1,4 @@
-from typing import TYPE_CHECKING, Callable
+from typing import TYPE_CHECKING
from trezor.enums import EthereumDataType
from trezor.wire import DataError
@@ -10,6 +10,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
+ from collections.abc import Callable
from trezor.messages import (
EthereumFieldType,
### core/src/apps/ethereum/staking.py
@@ -4,7 +4,8 @@
from trezor.wire import DataError
if TYPE_CHECKING:
- from typing import Any, Coroutine, Iterable
+ from collections.abc import Coroutine, Iterable
+ from typing import Any
from trezor.messages import EthereumNetworkInfo
from trezor.ui.layouts import StrPropertyType
### core/src/apps/ethereum/tokens.py
@@ -14,11 +14,14 @@
# of it has enough collision-resistance.)
# (In the if-tree approach the address length did not have any effect whatsoever.)
-from typing import Iterator
+from typing import TYPE_CHECKING
from trezor import utils
from trezor.messages import EthereumTokenInfo
+if TYPE_CHECKING:
+ from collections.abc import Iterator
+
UNKNOWN_TOKEN = EthereumTokenInfo(
symbol="Wei UNKN",
decimals=0,
### core/src/apps/ethereum/tokens.py.mako
@@ -14,10 +14,13 @@
# of it has enough collision-resistance.)
# (In the if-tree approach the address length did not have any effect whatsoever.)
-from typing import Iterator
+from typing import TYPE_CHECKING
from trezor import utils
from trezor.messages import EthereumTokenInfo
+
+if TYPE_CHECKING:
+ from collections.abc import Iterator
<%
from collections import defaultdict
### core/src/apps/ethereum/yielding.py
@@ -7,7 +7,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Any, Coroutine, Iterable
+ from collections.abc import Coroutine, Iterable
+ from typing import Any
from trezor.messages import EthereumNetworkInfo, EthereumTokenInfo
from trezor.ui.layouts import StrPropertyType
### core/src/apps/evolu/common.py
@@ -3,7 +3,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Sequence
+ from collections.abc import Sequence
ROTATION_INDEX_LIMIT = const((1 << 16) - 1)
### core/src/apps/homescreen/__init__.py
@@ -1,4 +1,4 @@
-from typing import Coroutine
+from typing import TYPE_CHECKING
import storage
import storage.device
@@ -12,6 +12,9 @@
from apps.common.authorization import is_set_any_session
from apps.common.lock_manager import can_lock_device, lock_device
+if TYPE_CHECKING:
+ from collections.abc import Coroutine
+
async def busyscreen() -> None:
await run_busyscreen(busy_expiry_ms())
### core/src/apps/management/backup_device.py
@@ -4,7 +4,7 @@
from trezor.enums import BackupType
if TYPE_CHECKING:
- from typing import Sequence
+ from collections.abc import Sequence
from trezor.messages import BackupDevice, BackupMethod, Success
### core/src/apps/management/change_language.py
@@ -4,7 +4,7 @@
from trezor.wire import DataError, high_speed
if TYPE_CHECKING:
- from typing import Callable
+ from collections.abc import Callable
from trezor.messages import ChangeLanguage, Success
from trezor.ui import ProgressLayout
### core/src/apps/management/change_pin.py
@@ -3,7 +3,7 @@
from trezor import TR, config, utils, wire
if TYPE_CHECKING:
- from typing import Awaitable
+ from collections.abc import Awaitable
from trezor.messages import ChangePin, Success
### core/src/apps/management/change_wipe_code.py
@@ -3,7 +3,7 @@
from trezor import TR
if TYPE_CHECKING:
- from typing import Awaitable
+ from collections.abc import Awaitable
from trezor.messages import ChangeWipeCode, Success
### core/src/apps/management/recovery_device/layout.py
@@ -18,7 +18,8 @@
from .recover import RecoveryAborted, load_slip39_state
if TYPE_CHECKING:
- from typing import Awaitable, Protocol
+ from collections.abc import Awaitable
+ from typing import Protocol
from trezor.enums import BackupMethod, BackupType, RecoveryType
### core/src/apps/management/recovery_device/word_validity.py
@@ -1,7 +1,7 @@
from typing import TYPE_CHECKING
if TYPE_CHECKING:
- from typing import Awaitable, Callable
+ from collections.abc import Awaitable, Callable
from trezor.enums import BackupType
### core/src/apps/management/reset_device/__init__.py
@@ -1,5 +1,5 @@
from micropython import const
-from typing import TYPE_CHECKING, Sequence
+from typing import TYPE_CHECKING
import storage
import storage.device as storage_device
@@ -19,6 +19,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
+ from collections.abc import Sequence
from trezor.messages import ResetDevice, Success
from trezor.ui.layouts import PropertyType
### core/src/apps/management/reset_device/layout.py
@@ -1,5 +1,5 @@
from micropython import const
-from typing import TYPE_CHECKING, Iterable, Protocol, Sequence
+from typing import TYPE_CHECKING, Protocol
from trezor import utils
from trezor.ui.layouts.reset import ( # noqa: F401
@@ -12,6 +12,8 @@
)
if TYPE_CHECKING:
+ from collections.abc import Iterable, Sequence
+
from trezor.messages import BackupMethod
_NUM_OF_CHOICES = const(3)
### core/src/apps/management/sd_protect.py
@@ -12,7 +12,7 @@
from apps.common.sdcard import ensure_sdcard
if TYPE_CHECKING:
- from typing import Awaitable
+ from collections.abc import Awaitable
from trezor.messages import SdProtect
### core/src/apps/monero/xmr/bulletproof.py
@@ -9,7 +9,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBuffer, AnyBytes
- from typing import Generic, Iterator, TypeVar
+ from collections.abc import Iterator
+ from typing import Generic, TypeVar
from .serialize_messages.tx_rsig_bulletproof import BulletproofPlus
### core/src/apps/nem/mosaic/nem_mosaics.py
@@ -5,10 +5,13 @@
# NOTE: not supplying the kwargs saves 120 bytes of code size
# `networks` needs kwarg as `levy` above is optional
-from typing import Iterator
+from typing import TYPE_CHECKING
from trezor.enums import NEMMosaicLevy
+if TYPE_CHECKING:
+ from collections.abc import Iterator
+
class MosaicLevy:
def __init__(
### core/src/apps/nem/mosaic/nem_mosaics.py.mako
@@ -5,10 +5,13 @@
# NOTE: not supplying the kwargs saves 120 bytes of code size
# `networks` needs kwarg as `levy` above is optional
-from typing import Iterator
+from typing import TYPE_CHECKING
from trezor.enums import NEMMosaicLevy
+if TYPE_CHECKING:
+ from collections.abc import Iterator
+
class MosaicLevy:
def __init__(
### core/src/apps/ripple/base58_ripple.py
@@ -1,7 +1,10 @@
-from typing import Callable
+from typing import TYPE_CHECKING
from trezor.crypto import base58
+if TYPE_CHECKING:
+ from collections.abc import Callable
+
# Ripple uses different 58 character alphabet than traditional base58
_ripple_alphabet = "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"
### core/src/apps/solana/layout.py
@@ -20,7 +20,7 @@
from .types import AddressType, is_address_reference
if TYPE_CHECKING:
- from typing import Sequence
+ from collections.abc import Sequence
from trezor.messages import PaymentRequest, SolanaOffchainMessageV1, SolanaTokenInfo
from trezor.ui.layouts import StrPropertyType
### core/src/apps/solana/types.py
@@ -3,8 +3,9 @@
from .definitions import Definitions
if TYPE_CHECKING:
+ from collections.abc import Callable
from enum import IntEnum
- from typing import Any, Callable, Generic, TypeVar
+ from typing import Any, Generic, TypeVar
from trezor.messages import SolanaTxAdditionalInfo, SolanaTxTokenAccountInfo
from trezor.utils import BufferReader
### core/src/apps/stellar/layout.py
@@ -11,7 +11,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Iterable
+ from collections.abc import Iterable
from trezor.enums import StellarMemoType
from trezor.messages import (
### core/src/apps/stellar/writers.py
@@ -13,7 +13,8 @@
if TYPE_CHECKING:
from buffer_types import StrOrBytes
- from typing import Callable, TypeVar
+ from collections.abc import Callable
+ from typing import TypeVar
from trezor.enums import StellarAssetType
from trezor.messages import (
### core/src/apps/thp/pairing.py
@@ -45,7 +45,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Any, Callable, Concatenate, ParamSpec
+ from collections.abc import Callable
+ from typing import Any, Concatenate, ParamSpec
from trezorui_api import UiResult
### core/src/apps/tron/consts.py
@@ -4,7 +4,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Iterator
+ from collections.abc import Iterator
TYPE_URL_TEMPLATE = "type.googleapis.com/protocol."
### core/src/apps/webauthn/credential.py
@@ -22,7 +22,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Iterable
+ from collections.abc import Iterable
from trezor.crypto import bip32
### core/src/apps/webauthn/fido2.py
@@ -18,7 +18,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Any, Awaitable, Callable, Coroutine, Iterable, Iterator
+ from collections.abc import Awaitable, Callable, Coroutine, Iterable, Iterator
+ from typing import Any
from .credential import U2fCredential
### core/src/apps/webauthn/resident_credentials.py
@@ -5,7 +5,7 @@
from storage.resident_credentials import MAX_RESIDENT_CREDENTIALS
if TYPE_CHECKING:
- from typing import Iterator
+ from collections.abc import Iterator
from .credential import Fido2Credential
### core/src/apps/zcash/hasher.py
@@ -21,7 +21,7 @@
)
if TYPE_CHECKING:
- from typing import Sequence
+ from collections.abc import Sequence
from trezor.messages import PrevTx, SignTx, TxInput, TxOutput
from trezor.utils import HashWriter, Writer
### core/src/apps/zcash/signer.py
@@ -7,7 +7,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Sequence
+ from collections.abc import Sequence
from trezor.messages import PrevTx, SignTx, TxInput, TxOutput
from trezor.utils import HashWriter
### core/src/prof/__main__.py
@@ -3,11 +3,12 @@
import vfs
from io import open
from os import getenv
-from typing import TYPE_CHECKING, Any, Callable, TypeAlias
+from typing import TYPE_CHECKING, Any, TypeAlias
import coveragedata
if TYPE_CHECKING:
+ from collections.abc import Callable
from types import FrameType
TraceFunction: TypeAlias = Callable[[FrameType, str, Any], "TraceFunction"]
### core/src/storage/cache_common.py
@@ -25,7 +25,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Sequence, TypeVar, overload
+ from collections.abc import Sequence
+ from typing import TypeVar, overload
T = TypeVar("T")
### core/src/storage/device.py
@@ -6,9 +6,9 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
+ from typing import Literal
from trezor.enums import BackupType, DisplayRotation
- from typing_extensions import Literal
# Namespace:
_NAMESPACE = common.APP_DEVICE
### core/src/storage/sd_salt.py
@@ -7,7 +7,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Callable, TypeVar
+ from collections.abc import Callable
+ from typing import TypeVar
T = TypeVar("T", bound=Callable)
### core/src/trezor/crypto/base58.py
@@ -17,7 +17,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Callable
+ from collections.abc import Callable
# 58 character alphabet used
_alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
### core/src/trezor/crypto/bech32.py
@@ -28,8 +28,9 @@
if TYPE_CHECKING:
+ from collections.abc import Sequence
from enum import IntEnum
- from typing import Sequence, TypeVar
+ from typing import TypeVar
A = TypeVar("A")
B = TypeVar("B")
### core/src/trezor/crypto/slip39.py
@@ -38,7 +38,7 @@
from trezor.errors import MnemonicError
if TYPE_CHECKING:
- from typing import Callable, Collection, Iterable
+ from collections.abc import Callable, Collection, Iterable
Indices = tuple[int, ...]
MnemonicGroups = dict[int, tuple[int, set[tuple[int, bytes]]]]
### core/src/trezor/loop.py
@@ -14,7 +14,8 @@
from trezor import io, log
if TYPE_CHECKING:
- from typing import Any, Awaitable, Callable, Coroutine, Generator, Generic, TypeVar
+ from collections.abc import Awaitable, Callable, Coroutine, Generator
+ from typing import Any, Generic, TypeVar
from .loop import wait
### core/src/trezor/sdcard.py
@@ -18,7 +18,8 @@ def capacity() -> int:
from typing import TYPE_CHECKING
if TYPE_CHECKING:
- from typing import Any, Callable, TypeVar
+ from collections.abc import Callable
+ from typing import Any, TypeVar
from typing_extensions import ParamSpec
### core/src/trezor/ui/__init__.py
@@ -20,7 +20,8 @@
from trezor.power_management.autodim import autodim_clear
if TYPE_CHECKING:
- from typing import Any, Callable, Generator, Generic, Iterator, TypeVar
+ from collections.abc import Callable, Generator, Iterator
+ from typing import Any, Generic, TypeVar
from trezor.enums import ButtonRequestType
from trezorui_api import LayoutContext, LayoutObj, UiResult # noqa: F401
### core/src/trezor/ui/layouts/bolt/__init__.py
@@ -11,7 +11,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes, StrOrBytes
- from typing import Awaitable, Iterable, NoReturn, Sequence
+ from collections.abc import Awaitable, Iterable, Sequence
+ from typing import NoReturn
from apps.stellar.tokens import StellarToken
### core/src/trezor/ui/layouts/bolt/reset.py
@@ -1,11 +1,14 @@
-from typing import Awaitable, Callable, Sequence
+from typing import TYPE_CHECKING
import trezorui_api
from trezor import TR
from trezor.enums import ButtonRequestType
from ..common import interact, raise_if_not_confirmed
+if TYPE_CHECKING:
+ from collections.abc import Awaitable, Callable, Sequence
+
CONFIRMED = trezorui_api.CONFIRMED # global_import_cache
### core/src/trezor/ui/layouts/caesar/__init__.py
@@ -10,7 +10,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes, StrOrBytes
- from typing import Awaitable, Callable, Iterable, NoReturn, Sequence
+ from collections.abc import Awaitable, Callable, Iterable, Sequence
+ from typing import NoReturn
from apps.stellar.tokens import StellarToken
### core/src/trezor/ui/layouts/caesar/recovery.py
@@ -10,7 +10,7 @@
from . import show_warning
if TYPE_CHECKING:
- from typing import Awaitable, Iterable
+ from collections.abc import Awaitable, Iterable
from apps.management.recovery_device.layout import RemainingSharesInfo
### core/src/trezor/ui/layouts/caesar/reset.py
@@ -10,7 +10,7 @@
CONFIRMED = trezorui_api.CONFIRMED # global_import_cache
if TYPE_CHECKING:
- from typing import Awaitable, Sequence
+ from collections.abc import Awaitable, Sequence
pass
### core/src/trezor/ui/layouts/common.py
@@ -6,7 +6,8 @@
from trezor.wire import ActionCancelled
if TYPE_CHECKING:
- from typing import Any, Awaitable, Callable, Coroutine, Literal, TypeVar, overload
+ from collections.abc import Awaitable, Callable, Coroutine
+ from typing import Any, Literal, TypeVar, overload
from trezorui_api import PropertyType, StrPropertyType # noqa: F401
### core/src/trezor/ui/layouts/delizia/__init__.py
@@ -15,7 +15,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes, StrOrBytes
- from typing import Awaitable, Iterable, NoReturn, Sequence, TypeVar
+ from collections.abc import Awaitable, Iterable, Sequence
+ from typing import NoReturn, TypeVar
from apps.stellar.tokens import StellarToken
### core/src/trezor/ui/layouts/delizia/reset.py
@@ -1,4 +1,4 @@
-from typing import Awaitable, Callable, Sequence
+from typing import TYPE_CHECKING
import trezorui_api
from trezor import TR, ui
@@ -8,6 +8,9 @@
from ..common import interact
from . import raise_if_not_confirmed, show_success
+if TYPE_CHECKING:
+ from collections.abc import Awaitable, Callable, Sequence
+
CONFIRMED = trezorui_api.CONFIRMED # global_import_cache
### core/src/trezor/ui/layouts/eckhart/__init__.py
@@ -15,7 +15,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes, StrOrBytes
- from typing import Awaitable, Iterable, NoReturn, Sequence, TypeVar
+ from collections.abc import Awaitable, Iterable, Sequence
+ from typing import NoReturn, TypeVar
from trezor.ui.layouts.menu import Details
### core/src/trezor/ui/layouts/eckhart/reset.py
@@ -1,4 +1,4 @@
-from typing import Awaitable, Callable, Sequence
+from typing import TYPE_CHECKING
import trezorui_api
from trezor import TR, ui
@@ -8,6 +8,9 @@
from ..common import interact
from . import raise_if_not_confirmed, show_success
+if TYPE_CHECKING:
+ from collections.abc import Awaitable, Callable, Sequence
+
CONFIRMED = trezorui_api.CONFIRMED # global_import_cache
### core/src/trezor/ui/layouts/homescreen.py
@@ -6,7 +6,8 @@
from trezor import TR, ui, utils
if TYPE_CHECKING:
- from typing import Any, Callable, Iterator, ParamSpec, TypeVar
+ from collections.abc import Callable, Iterator
+ from typing import Any, ParamSpec, TypeVar
from trezor import loop
### core/src/trezor/ui/layouts/menu.py
@@ -1,4 +1,4 @@
-from typing import TYPE_CHECKING, Awaitable
+from typing import TYPE_CHECKING
import trezorui_api
from trezor.enums import ButtonRequestType
@@ -7,7 +7,8 @@
from trezor.wire import ActionCancelled
if TYPE_CHECKING:
- from typing import Callable, Iterable, Sequence, TypeVar
+ from collections.abc import Awaitable, Callable, Iterable, Sequence
+ from typing import TypeVar
from typing_extensions import Self
### core/src/trezor/ui/layouts/properties.py
@@ -3,7 +3,8 @@
from trezor import translations, utils
if TYPE_CHECKING:
- from typing import Iterable, overload
+ from collections.abc import Iterable
+ from typing import overload
from .common import StrPropertyType
### core/src/trezor/utils.py
@@ -104,7 +104,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBuffer, AnyBytes
- from typing import Any, Iterator, Protocol, Sequence, TypeVar
+ from collections.abc import Iterator, Sequence
+ from typing import Any, Protocol, TypeVar
from trezor.protobuf import MessageType
### core/src/trezor/wire/__init__.py
@@ -48,9 +48,10 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
+ from collections.abc import Callable, Coroutine
from trezorio import WireInterface
from types import TracebackType
- from typing import Any, Callable, Coroutine, Generic, TypeVar
+ from typing import Any, Generic, TypeVar
from trezor.wire.thp.channel import Channel
from trezor.wire.thp.interface_context import InterfaceContext
### core/src/trezor/wire/codec/codec_context.py
@@ -1,4 +1,4 @@
-from typing import TYPE_CHECKING, Awaitable, Container
+from typing import TYPE_CHECKING
from trezor import protobuf, utils
from trezor.wire.codec import codec_v1
@@ -11,6 +11,7 @@
if TYPE_CHECKING:
+ from collections.abc import Awaitable, Container
from typing import TypeVar
from storage.cache_common import DataCache
### core/src/trezor/wire/codec/codec_v1.py
@@ -7,8 +7,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBuffer, AnyBytes
+ from collections.abc import Callable
from trezorio import WireInterface
- from typing import Callable
_REP_MARKER = const(63) # ord('?')
_REP_MAGIC = const(35) # org('#')
### core/src/trezor/wire/context.py
@@ -19,7 +19,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Any, Callable, Coroutine, Generator, TypeVar, overload
+ from collections.abc import Callable, Coroutine, Generator
+ from typing import Any, TypeVar, overload
from storage.cache_common import DataCache
### core/src/trezor/wire/message_handler.py
@@ -11,7 +11,8 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Any, Callable, Container
+ from collections.abc import Callable, Container
+ from typing import Any
from trezor.wire import Handler, LoadedMessageType, WireInterface
### core/src/trezor/wire/protocol_common.py
@@ -8,17 +8,9 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
+ from collections.abc import Awaitable, Callable, Container
from trezorio import WireInterface
- from typing import (
- Any,
- Awaitable,
- Callable,
- Container,
- Literal,
- NoReturn,
- TypeVar,
- overload,
- )
+ from typing import Any, Literal, NoReturn, TypeVar, overload
from storage.cache_common import DataCache
from trezor.messages import ButtonRequest
### core/src/trezor/wire/thp/interface_context.py
@@ -20,8 +20,9 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
+ from collections.abc import Generator
from trezorio import WireInterface
- from typing import Any, Generator
+ from typing import Any
_TRACE = const(False)
### core/src/trezor/wire/thp/pairing_context.py
@@ -14,7 +14,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Awaitable, Container
+ from collections.abc import Awaitable, Container
from trezor.enums import ThpPairingMethod
from trezorui_api import UiResult
### core/src/trezor/wire/thp/session_context.py
@@ -12,7 +12,7 @@
from . import SessionState
if TYPE_CHECKING:
- from typing import Awaitable, Container
+ from collections.abc import Awaitable, Container
from storage.cache_common import DataCache
### core/src/trezor/wire/thp/ui.py
@@ -1,7 +1,7 @@
from typing import TYPE_CHECKING
if TYPE_CHECKING:
- from typing import Awaitable
+ from collections.abc import Awaitable
from trezorui_api import UiResult
### core/src/trezor/workflow.py
@@ -6,7 +6,8 @@
from trezor.enums import MessageType
if TYPE_CHECKING:
- from typing import Callable, TypeVar
+ from collections.abc import Callable
+ from typing import TypeVar
IdleCallback = Callable[[], None]
T = TypeVar("T")
### core/tests/common.py
@@ -1,11 +1,14 @@
import unittest # noqa: F401
-from typing import Any, Awaitable
+from typing import TYPE_CHECKING, Any
from trezor import utils # noqa: F401
from trezor.wire import context
from apps.common.paths import HARDENED
+if TYPE_CHECKING:
+ from collections.abc import Awaitable
+
def H_(x: int) -> int:
"""
### core/tests/cosi_helpers.py
@@ -4,7 +4,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Sequence
+ from collections.abc import Sequence
commit = ed25519.cosi_commit
### core/tests/test_apps.common.payment_request.py
@@ -20,7 +20,8 @@
from apps.common.payment_request import PaymentRequestVerifier
if TYPE_CHECKING:
- from typing import Callable, ParamSpec
+ from collections.abc import Callable
+ from typing import ParamSpec
P = ParamSpec("P")
### core/tools/analyze-memory-dump.py
@@ -5,9 +5,8 @@
import json
import sys
-from typing import Any, Iterator, Optional
-
-from typing_extensions import TypeGuard
+from collections.abc import Iterator
+from typing import Any, Optional, TypeGuard
if len(sys.argv) < 2:
print("""\
### core/tools/make_cmakelists.py
@@ -1,5 +1,5 @@
import argparse
-from typing import Iterable
+from collections.abc import Iterable
def gen(sources: Iterable[str], dirs: Iterable[str], defs: Iterable[str]) -> None:
### core/tools/size/groups.py
@@ -6,8 +6,8 @@
from __future__ import annotations
import sys
+from collections.abc import Callable
from pathlib import Path
-from typing import Callable
from binsize import BinarySize, DataRow, StatisticsPlugin, set_root_dir
### core/tools/trezor_core_tools/hash_signer.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
from __future__ import annotations
-from typing import Sequence
+from collections.abc import Sequence
import click
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.