chore(core): enforce PEP 585 style [UP006]
What changed, and why it matters
This commit is a routine code cleanup that updates Python type annotations to a newer, recommended style. It does not change what the code actually does, only how type hints are written. There is no security issue here.
No action required. This is a non-functional style refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit replaces deprecated typing module generics (e.g., typing.Type, typing.Tuple, typing.List, typing.Dict) with PEP 585 built-in collection types (type, tuple, list, dict). These changes are purely syntactic and occur under TYPE_CHECKING blocks or in type-only contexts. Runtime behavior is unchanged. No functional code paths, validation logic, or cryptographic operations are modified.
Changed components
core/src/apps/cardano/sign_tx/__init__.pycore/src/apps/solana/predefined_transaction.pycore/src/apps/solana/transaction/instructions.pycore/src/apps/solana/transaction/instructions.py.makocore/src/apps/tron/consts.pycore/src/apps/tron/sign_tx.pycore/src/trezor/ui/layouts/homescreen.pycore/src/trezor/wire/__init__.pycore/tools/alloc.pycore/tools/generate_tropic_config_docs.pycore/tools/trezor_core_tools/headertool.pyInspect captured patch +18 / −23
### core/src/apps/cardano/sign_tx/__init__.py
@@ -3,8 +3,6 @@
from .. import seed
if TYPE_CHECKING:
- from typing import Type
-
from trezor.messages import CardanoSignTxFinished, CardanoSignTxInit
from apps.common.keychain import Keychain as Slip21Keychain
@@ -23,7 +21,7 @@ async def sign_tx(
signing_mode = msg.signing_mode # local_cache_attribute
- signer_type: Type[Signer]
+ signer_type: type[Signer]
if signing_mode == CardanoTxSigningMode.ORDINARY_TRANSACTION:
from .ordinary_signer import OrdinarySigner
### core/src/apps/solana/predefined_transaction.py
@@ -16,7 +16,6 @@
from .types import is_address_reference
if TYPE_CHECKING:
- from typing import Type
from trezor.messages import PaymentRequest
@@ -288,7 +287,7 @@ async def try_confirm_staking_transaction(
if not instructions:
return False
- def _match_instructions(*expected_types: Type[Instruction]) -> bool:
+ def _match_instructions(*expected_types: type[Instruction]) -> bool:
if len(instructions) != len(expected_types):
return False
return all(
### core/src/apps/solana/transaction/instructions.py
@@ -22,7 +22,7 @@
from .parse import parse_byte, parse_memo, parse_pubkey, parse_string
if TYPE_CHECKING:
- from typing import Any, Type, TypeGuard
+ from typing import Any, TypeGuard
from ..types import Account, InstructionData, InstructionId
@@ -141,7 +141,7 @@ def is_atap_account_creation(instruction: Instruction) -> bool:
)
-def __getattr__(name: str) -> Type[Instruction]:
+def __getattr__(name: str) -> type[Instruction]:
def get_id(name: str) -> tuple[str, InstructionId]:
if name == "SystemProgramCreateAccountInstruction":
return (_SYSTEM_PROGRAM_ID, _SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT)
### core/src/apps/solana/transaction/instructions.py.mako
@@ -61,7 +61,7 @@ from .parse import (
)
if TYPE_CHECKING:
- from typing import Any, Type, TypeGuard
+ from typing import Any, TypeGuard
from ..types import Account, InstructionId, InstructionData
@@ -106,7 +106,7 @@ def is_atap_account_creation(instruction: Instruction) -> bool:
)
-def __getattr__(name: str) -> Type[Instruction]:
+def __getattr__(name: str) -> type[Instruction]:
def get_id(name: str) -> tuple[str, InstructionId]:
%for program in programs["programs"]:
%for instruction in program["instructions"]:
### core/src/apps/tron/consts.py
@@ -4,7 +4,7 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Iterator, Tuple
+ from typing import Iterator
TYPE_URL_TEMPLATE = "type.googleapis.com/protocol."
@@ -62,7 +62,7 @@ def get_contract_type_name(contract_type: int) -> str:
_KLEVER_ADDRESS = b"\x41\xd8\xb8\x08\x98\x56\xce\xd3\x03\x86\x01\xcb\xeb\x1e\x3f\x76\x5c\xab\xc1\x2a\x41"
-def token_iterator() -> Iterator[Tuple[AnyBytes, int, str]]:
+def token_iterator() -> Iterator[tuple[AnyBytes, int, str]]:
yield (_SHASTA_USDT_ADDRESS, 6, "tUSDT")
yield (_USDT_ADDRESS, 6, "USDT")
yield (_USDD_ADDRESS, 18, "USDD")
### core/src/apps/tron/sign_tx.py
@@ -11,7 +11,6 @@
if TYPE_CHECKING:
from buffer_types import AnyBytes
- from typing import Tuple
from trezor.messages import (
TronRawContract,
@@ -384,7 +383,7 @@ async def _validate_tx_fields(msg: TronSignTx) -> None:
)
-def get_token_info(token_address: AnyBytes) -> Tuple[int, str] | None:
+def get_token_info(token_address: AnyBytes) -> tuple[int, str] | None:
for address, decimals, symbol in consts.token_iterator():
if token_address == address:
return decimals, symbol
### core/src/trezor/ui/layouts/homescreen.py
@@ -6,7 +6,7 @@
from trezor import TR, ui, utils
if TYPE_CHECKING:
- from typing import Any, Callable, Iterator, ParamSpec, Tuple, TypeVar
+ from typing import Any, Callable, Iterator, ParamSpec, TypeVar
from trezor import loop
@@ -97,7 +97,7 @@ def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
async def run_homescreen(
label: str | None,
- notification: Tuple[str, int, bool] | None,
+ notification: tuple[str, int, bool] | None,
lockable: bool,
) -> ui.UiResult:
class Homescreen(HomescreenBase):
### core/src/trezor/wire/__init__.py
@@ -50,7 +50,7 @@
from buffer_types import AnyBytes
from trezorio import WireInterface
from types import TracebackType
- from typing import Any, Callable, Coroutine, Generic, Type, TypeVar
+ from typing import Any, Callable, Coroutine, Generic, TypeVar
from trezor.wire.thp.channel import Channel
from trezor.wire.thp.interface_context import InterfaceContext
@@ -76,7 +76,7 @@ def __enter__(self) -> "_HighSpeed":
def __exit__(
self,
- exc_type: Type[BaseException] | None,
+ exc_type: type[BaseException] | None,
exc: BaseException | None,
tb: TracebackType | None,
) -> bool:
### core/tools/alloc.py
@@ -5,7 +5,7 @@
from pathlib import Path
from types import SimpleNamespace
-from typing import TYPE_CHECKING, Dict, Protocol, TextIO, TypedDict
+from typing import TYPE_CHECKING, Protocol, TextIO, TypedDict
import click
from dominate import document
@@ -23,7 +23,7 @@ class LineAllocData(TypedDict):
avg_allocs: float
# {filename:{lineno:LineAllocData}}
- alloc_data_dict = Dict[str, Dict[int, LineAllocData]]
+ alloc_data_dict = dict[str, dict[int, LineAllocData]]
class SharedObject(Protocol):
data: alloc_data_dict
### core/tools/generate_tropic_config_docs.py
@@ -4,7 +4,6 @@
import tempfile
from io import TextIOWrapper
from pathlib import Path
-from typing import List
import click
@@ -24,7 +23,7 @@
"""
-def print_value_lines(value_lines: List[List[str]], md_file: TextIOWrapper) -> None:
+def print_value_lines(value_lines: list[list[str]], md_file: TextIOWrapper) -> None:
col_count = max(len(line) for line in value_lines)
col_len = [max(len(line[i]) for line in value_lines) for i in range(col_count)]
### core/tools/trezor_core_tools/headertool.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
from __future__ import annotations
-from typing import Any, BinaryIO, List, Tuple
+from typing import Any, BinaryIO
import click
@@ -11,7 +11,7 @@
# =========================== signing =========================
-def parse_privkey_args(privkey_data: List[str]) -> Tuple[int, List[bytes]]:
+def parse_privkey_args(privkey_data: list[str]) -> tuple[int, list[bytes]]:
privkeys = []
sigmask = 0
for key in privkey_data: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.