style: update to black 25 style, silence new flake8 warnings
What changed, and why it matters
This commit is purely a code-style update. It reformats Python source files to match the latest version of the Black formatter, changes uppercase hex escapes in byte strings to lowercase, removes unnecessary 'global' declarations, and adjusts some 'with' statements and trailing commas to satisfy updated flake8 rules. There are no functional changes to the firmware, tests, or tooling.
No security action needed. This is a routine style/linting maintenance commit. Reviewers may verify that CI passes and that no unintended functional changes were introduced by the formatter.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff shows only stylistic changes: Black 25 reformatting (lowercasing hex escapes in bytes literals, trailing commas in function signatures and ‘with’ statements), removal of redundant ‘global’ statements, and a flake8 noqa suppression in Monero CLSAG code. No logic, constants, security checks, or behavior is altered. The commit message explicitly labels this as a style change with ‘[no changelog]’.
Changed components
core/src/apps/bitcoin/sign_tx/bitcoin.pycore/src/apps/bitcoin/sign_tx/decred.pycore/src/apps/bitcoin/sign_tx/layout.pycore/src/apps/cardano/layout.pycore/src/apps/common/mnemonic.pycore/src/apps/ethereum/keychain.pycore/src/apps/monero/xmr/clsag.pycore/src/apps/solana/layout.pycore/src/apps/stellar/layout.pycore/src/storage/cache_codec.pycore/src/storage/cache_thp.pycore/src/trezor/ui/__init__.pycore/src/trezor/workflow.pycore/tests/*crypto/fuzzer/extract_fuzzer_dictionary.pylegacy/bootloader/firmware_sign.pylegacy/bootloader/firmware_sign_dev.pystorage/tests/python/*storage/tests/tests/*tests/device_tests/*tests/upgrade_tests/*tools/changelog.pyInspect captured patch +112 / −106
diff --git a/core/src/apps/bitcoin/sign_tx/bitcoin.py b/core/src/apps/bitcoin/sign_tx/bitcoin.py
index 83efd253..4f2bdbe2 100644
--- a/core/src/apps/bitcoin/sign_tx/bitcoin.py
+++ b/core/src/apps/bitcoin/sign_tx/bitcoin.py
@@ -115,8 +115,6 @@ class Bitcoin:
from . import approvers
from .tx_info import TxInfo
- global _SERIALIZED_TX_BUFFER
-
self.tx_info = TxInfo(self, helpers.sanitize_sign_tx(tx, coin))
self.keychain = keychain
self.coin = coin
diff --git a/core/src/apps/bitcoin/sign_tx/decred.py b/core/src/apps/bitcoin/sign_tx/decred.py
index 39b99380..f0613f47 100644
--- a/core/src/apps/bitcoin/sign_tx/decred.py
+++ b/core/src/apps/bitcoin/sign_tx/decred.py
@@ -22,7 +22,7 @@ _DECRED_SERIALIZE_NO_WITNESS = const(1 << 16)
_DECRED_SERIALIZE_WITNESS_SIGNING = const(3 << 16)
_DECRED_SCRIPT_VERSION = const(0)
OUTPUT_SCRIPT_NULL_SSTXCHANGE = (
- b"\xBD\x76\xA9\x14\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x88\xAC"
+ b"\xbd\x76\xa9\x14\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x88\xac"
)
if TYPE_CHECKING:
diff --git a/core/src/apps/bitcoin/sign_tx/layout.py b/core/src/apps/bitcoin/sign_tx/layout.py
index 3f3dcb19..40090c05 100644
--- a/core/src/apps/bitcoin/sign_tx/layout.py
+++ b/core/src/apps/bitcoin/sign_tx/layout.py
@@ -191,8 +191,8 @@ async def show_payment_request_details(
)
trades.append(
(
- f"-\u00A0{total_amount}",
- f"+\u00A0{memo.coin_purchase_memo.amount}",
+ f"-\u00a0{total_amount}",
+ f"+\u00a0{memo.coin_purchase_memo.amount}",
memo.coin_purchase_memo.address,
coin_purchase_account,
coin_purchase_account_path,
diff --git a/core/src/apps/cardano/layout.py b/core/src/apps/cardano/layout.py
index 164c1ea3..692c71a2 100644
--- a/core/src/apps/cardano/layout.py
+++ b/core/src/apps/cardano/layout.py
@@ -1230,8 +1230,8 @@ async def require_confirm_payment_request(
)
trades.append(
(
- f"-\u00A0{total_amount}",
- f"+\u00A0{memo.coin_purchase_memo.amount}",
+ f"-\u00a0{total_amount}",
+ f"+\u00a0{memo.coin_purchase_memo.amount}",
memo.coin_purchase_memo.address,
None,
coin_purchase_account_path,
diff --git a/core/src/apps/common/mnemonic.py b/core/src/apps/common/mnemonic.py
index 4707d73e..a33b0ee5 100644
--- a/core/src/apps/common/mnemonic.py
+++ b/core/src/apps/common/mnemonic.py
@@ -116,7 +116,6 @@ def _start_progress() -> None:
def _render_progress(progress: int, total: int) -> None:
- global _progress_obj
if _progress_obj is not None:
_progress_obj.report(1000 * progress // total)
diff --git a/core/src/apps/ethereum/keychain.py b/core/src/apps/ethereum/keychain.py
index 60544298..f8183f02 100644
--- a/core/src/apps/ethereum/keychain.py
+++ b/core/src/apps/ethereum/keychain.py
@@ -118,7 +118,7 @@ def with_keychain_from_path(
*patterns: str,
) -> Callable[[HandlerAddressN[MsgInAddressN, MsgOut]], Handler[MsgInAddressN, MsgOut]]:
def decorator(
- func: HandlerAddressN[MsgInAddressN, MsgOut]
+ func: HandlerAddressN[MsgInAddressN, MsgOut],
) -> Handler[MsgInAddressN, MsgOut]:
async def wrapper(msg: MsgInAddressN) -> MsgOut:
slip44 = _slip44_from_address_n(msg.address_n)
@@ -134,7 +134,7 @@ def with_keychain_from_path(
def with_keychain_from_chain_id(
- func: HandlerChainId[MsgInSignTx, MsgOut]
+ func: HandlerChainId[MsgInSignTx, MsgOut],
) -> Handler[MsgInSignTx, MsgOut]:
# this is only for SignTx, and only PATTERN_ADDRESS is allowed
async def wrapper(msg: MsgInSignTx) -> MsgOut:
diff --git a/core/src/apps/monero/xmr/clsag.py b/core/src/apps/monero/xmr/clsag.py
index b431df3e..144f06cd 100644
--- a/core/src/apps/monero/xmr/clsag.py
+++ b/core/src/apps/monero/xmr/clsag.py
@@ -153,7 +153,9 @@ def _generate_clsag(
hsh_C.update(_HASH_KEY_CLSAG_AGG_1)
def hsh_PC(x):
- nonlocal hsh_P, hsh_C
+ nonlocal hsh_P, hsh_C # noqa: F824
+ # TODO flake8 is confused here, without the nonlocal declaration it complains
+ # that `hsh_P/C` is undefined, and with it it complains about useless nonlocal
hsh_P.update(x)
hsh_C.update(x)
diff --git a/core/src/apps/solana/layout.py b/core/src/apps/solana/layout.py
index 58fd2810..d1bd9e2c 100644
--- a/core/src/apps/solana/layout.py
+++ b/core/src/apps/solana/layout.py
@@ -560,8 +560,8 @@ async def confirm_payment_request(
)
trades.append(
(
- f"-\u00A0{total_amount}",
- f"+\u00A0{memo.coin_purchase_memo.amount}",
+ f"-\u00a0{total_amount}",
+ f"+\u00a0{memo.coin_purchase_memo.amount}",
memo.coin_purchase_memo.address,
None,
coin_purchase_account_path,
diff --git a/core/src/apps/stellar/layout.py b/core/src/apps/stellar/layout.py
index 8ac91718..d80c6511 100644
--- a/core/src/apps/stellar/layout.py
+++ b/core/src/apps/stellar/layout.py
@@ -86,8 +86,8 @@ async def require_confirm_payment_request(
)
trades.append(
(
- f"-\u00A0{total_amount}",
- f"+\u00A0{memo.coin_purchase_memo.amount}",
+ f"-\u00a0{total_amount}",
+ f"+\u00a0{memo.coin_purchase_memo.amount}",
memo.coin_purchase_memo.address,
None,
coin_purchase_account_path,
diff --git a/core/src/storage/cache_codec.py b/core/src/storage/cache_codec.py
index 7be59890..f6402b4d 100644
--- a/core/src/storage/cache_codec.py
+++ b/core/src/storage/cache_codec.py
@@ -70,7 +70,6 @@ def initialize() -> None:
# sized bytearrays, then call `clear()` on all existing objects, which
# resets them to zero length. The `clear()` function uses `arr[:]`, which
# allocates a slice.
- global _SESSIONS
for _ in range(_MAX_SESSIONS_COUNT):
_SESSIONS.append(SessionCache())
diff --git a/core/src/storage/cache_thp.py b/core/src/storage/cache_thp.py
index 6d68c837..9231164d 100644
--- a/core/src/storage/cache_thp.py
+++ b/core/src/storage/cache_thp.py
@@ -122,8 +122,6 @@ _usage_counter = 0
def initialize() -> None:
- global _CHANNELS
- global _SESSIONS
global cid_counter
for _ in range(_MAX_CHANNELS_COUNT):
@@ -338,7 +336,6 @@ def get_next_channel_id() -> bytes:
def _is_cid_unique() -> bool:
- global cid_counter
cid_counter_bytes = cid_counter.to_bytes(_CHANNEL_ID_LENGTH, "big")
for channel in _CHANNELS:
if channel.channel_id == cid_counter_bytes:
@@ -347,7 +344,6 @@ def _is_cid_unique() -> bool:
def _get_least_recently_used_item(list: Sequence[ThpDataCache], max_count: int) -> int:
- global _usage_counter
lru_counter = _usage_counter + 1
lru_item_index = 0
for i in range(max_count):
diff --git a/core/src/trezor/ui/__init__.py b/core/src/trezor/ui/__init__.py
index 4d3cd89c..df257ab6 100644
--- a/core/src/trezor/ui/__init__.py
+++ b/core/src/trezor/ui/__init__.py
@@ -184,8 +184,6 @@ class Layout(Generic[T]):
If the layout is already RUNNING, do nothing. If the layout is FINISHED, fail.
"""
- global CURRENT_LAYOUT
-
# do nothing if we are already running
if self.is_running():
return
@@ -229,8 +227,6 @@ class Layout(Generic[T]):
set to False to indicate that a result became available and that the taker
should be allowed to pick it up.
"""
- global CURRENT_LAYOUT
-
# stop all running timers and spawned tasks
for timer in self.timers.values():
loop.close(timer)
@@ -585,8 +581,6 @@ class ProgressLayout:
self.value = value
def start(self) -> None:
- global CURRENT_LAYOUT
-
if CURRENT_LAYOUT is not self and CURRENT_LAYOUT is not None:
CURRENT_LAYOUT.stop()
@@ -598,7 +592,5 @@ class ProgressLayout:
backlight_fade(BacklightLevels.NORMAL)
def stop(self) -> None:
- global CURRENT_LAYOUT
-
if CURRENT_LAYOUT is self:
set_current_layout(None)
diff --git a/core/src/trezor/workflow.py b/core/src/trezor/workflow.py
index f97e2a90..2570bc61 100644
--- a/core/src/trezor/workflow.py
+++ b/core/src/trezor/workflow.py
@@ -110,7 +110,6 @@ def start_default() -> None:
If a default task is already running, nothing will happen.
"""
global default_task
- global default_constructor
global autolock_interrupts_workflow
assert default_constructor is not None
diff --git a/core/tests/test_apps.ethereum.tokens.py b/core/tests/test_apps.ethereum.tokens.py
index 7065ca13..ac3f85ef 100644
--- a/core/tests/test_apps.ethereum.tokens.py
+++ b/core/tests/test_apps.ethereum.tokens.py
@@ -16,7 +16,7 @@ class TestEthereumTokens(unittest.TestCase):
self.assertEqual(token.symbol, "AAVE")
# invalid adress, invalid chain
- token = tokens.token_by_chain_address(999, b"\x00\xFF")
+ token = tokens.token_by_chain_address(999, b"\x00\xff")
self.assertIs(token, None)
self.assertEqual(tokens.UNKNOWN_TOKEN.symbol, "Wei UNKN")
diff --git a/core/tests/test_apps.thp.credential_manager.py b/core/tests/test_apps.thp.credential_manager.py
index 1dfacd93..50e9e05e 100644
--- a/core/tests/test_apps.thp.credential_manager.py
+++ b/core/tests/test_apps.thp.credential_manager.py
@@ -82,7 +82,7 @@ class TestTrezorHostProtocolCredentialManager(unittest.TestCase):
expected = b"\x0a\x0b\x0a\x09\x68\x6f\x73\x74\x5f\x6e\x61\x6d\x65\x12\x20\xf4\x44\x86\x2d\x00\x23\x1d\x02\xf3\x20\xbb\x58\xed\x13\x8f\xc6\x84\x9b\x6b\x73\x7a\x33\x25\xc4\x71\x79\x3b\x45\x15\xe4\x76\x67"
# Use hard-coded bytes as a "credential auth key" when issuing a credential
- credential_manager.derive_cred_auth_key = lambda: b"\xBE\xEF"
+ credential_manager.derive_cred_auth_key = lambda: b"\xbe\xef"
credential = _issue_credential(HOST_NAME_1, DUMMY_KEY_1)
self.assertEqual(credential, expected)
diff --git a/core/tests/test_trezor.crypto.bech32.py b/core/tests/test_trezor.crypto.bech32.py
index e9d56bca..f8bb4dbd 100644
--- a/core/tests/test_trezor.crypto.bech32.py
+++ b/core/tests/test_trezor.crypto.bech32.py
@@ -71,7 +71,7 @@ VALID_CHECKSUM = [
INVALID_CHECKSUM = [
# BIP-173
" 1nwldj5",
- "\x7F" + "1axkwrx",
+ "\x7f" + "1axkwrx",
"\x80" + "1eym55h",
"an84characterslonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1569pvx",
"pzry9x0s0muk",
@@ -84,7 +84,7 @@ INVALID_CHECKSUM = [
"1qzzfhee",
# BIP-350
" 1xj0phk",
- "\x7F" + "1g6xzxy",
+ "\x7f" + "1g6xzxy",
"\x80" + "1vctc34",
"an84characterslonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11d6pts4",
"qyrz8wqd2c9m",
diff --git a/core/tests/test_trezor.crypto.curve.bip340.py b/core/tests/test_trezor.crypto.curve.bip340.py
index 2f29d619..f2596a7c 100644
--- a/core/tests/test_trezor.crypto.curve.bip340.py
+++ b/core/tests/test_trezor.crypto.curve.bip340.py
@@ -33,7 +33,7 @@ class TestCryptoBip340(unittest.TestCase):
self.assertTrue(sk != b"\x00" * 32)
self.assertTrue(
sk
- < b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFE\xBA\xAE\xDC\xE6\xAF\x48\xA0\x3B\xBF\xD2\x5E\x8C\xD0\x36\x41\x41"
+ < b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xba\xae\xdc\xe6\xaf\x48\xa0\x3b\xbf\xd2\x5e\x8c\xd0\x36\x41\x41"
)
def test_publickey(self):
diff --git a/core/tests/test_trezor.crypto.curve.nist256p1.py b/core/tests/test_trezor.crypto.curve.nist256p1.py
index c15535f7..0e893b34 100644
--- a/core/tests/test_trezor.crypto.curve.nist256p1.py
+++ b/core/tests/test_trezor.crypto.curve.nist256p1.py
@@ -226,7 +226,7 @@ class TestCryptoNist256p1(unittest.TestCase):
self.assertTrue(sk != b"\x00" * 32)
self.assertTrue(
sk
- < b"\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xBC\xE6\xFA\xAD\xA7\x17\x9E\x84\xF3\xB9\xCA\xC2\xFC\x63\x25\x51"
+ < b"\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xbc\xe6\xfa\xad\xa7\x17\x9e\x84\xf3\xb9\xca\xc2\xfc\x63\x25\x51"
)
def test_publickey(self):
diff --git a/core/tests/test_trezor.crypto.curve.secp256k1.py b/core/tests/test_trezor.crypto.curve.secp256k1.py
index ebdbea8a..518502b8 100644
--- a/core/tests/test_trezor.crypto.curve.secp256k1.py
+++ b/core/tests/test_trezor.crypto.curve.secp256k1.py
@@ -197,7 +197,7 @@ class TestCryptoSecp256k1(unittest.TestCase):
self.assertTrue(sk != b"\x00" * 32)
self.assertTrue(
sk
- < b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFE\xBA\xAE\xDC\xE6\xAF\x48\xA0\x3B\xBF\xD2\x5E\x8C\xD0\x36\x41\x41"
+ < b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xba\xae\xdc\xe6\xaf\x48\xa0\x3b\xbf\xd2\x5e\x8c\xd0\x36\x41\x41"
)
def test_publickey(self):
diff --git a/crypto/fuzzer/extract_fuzzer_dictionary.py b/crypto/fuzzer/extract_fuzzer_dictionary.py
index 6a958351..adb74761 100755
--- a/crypto/fuzzer/extract_fuzzer_dictionary.py
+++ b/crypto/fuzzer/extract_fuzzer_dictionary.py
@@ -270,7 +270,6 @@ def print_verbose(text):
def recursive_dictionary_extraction(directory):
"""handle the central extraction logic"""
# TODO split this function up into subfunctions
- global counter_hex_content
# handle as a set structure to de-duplicate results automatically
candidate_lines = set()
diff --git a/legacy/bootloader/firmware_sign.py b/legacy/bootloader/firmware_sign.py
index a19e73e9..b58f3f55 100755
--- a/legacy/bootloader/firmware_sign.py
+++ b/legacy/bootloader/firmware_sign.py
@@ -51,7 +51,7 @@ def pad_to_size(data, size):
raise ValueError("Chunk too big already")
if len(data) == size:
return data
- return data + b"\xFF" * (size - len(data))
+ return data + b"\xff" * (size - len(data))
# see memory.h for details
diff --git a/legacy/bootloader/firmware_sign_dev.py b/legacy/bootloader/firmware_sign_dev.py
index af66ce1e..393fc83d 100644
--- a/legacy/bootloader/firmware_sign_dev.py
+++ b/legacy/bootloader/firmware_sign_dev.py
@@ -42,7 +42,7 @@ def pad_to_size(data, size):
raise ValueError("Chunk too big already")
if len(data) == size:
return data
- return data + b"\xFF" * (size - len(data))
+ return data + b"\xff" * (size - len(data))
# see memory.h for details
diff --git a/storage/tests/python/src/consts.py b/storage/tests/python/src/consts.py
index dae6e577..2d067392 100644
--- a/storage/tests/python/src/consts.py
+++ b/storage/tests/python/src/consts.py
@@ -93,8 +93,8 @@ WORD_SIZE = 4
# Boolean values are stored as a simple 0/1 int.
TRUE_BYTE = b"\x01"
FALSE_BYTE = b"\x00"
-TRUE_WORD = b"\xA5\x69\x5A\xC3"
-FALSE_WORD = b"\x5A\x96\xA5\x3C"
+TRUE_WORD = b"\xa5\x69\x5a\xc3"
+FALSE_WORD = b"\x5a\x96\xa5\x3c"
# ----- Crypto ----- #
diff --git a/storage/tests/python/src/norcow.py b/storage/tests/python/src/norcow.py
index d49a7639..de9e840c 100644
--- a/storage/tests/python/src/norcow.py
+++ b/storage/tests/python/src/norcow.py
@@ -292,7 +292,7 @@ class NorcowBlockwise(Norcow):
data = align_data(
pack("<HH", key, len(new_value)), self.block_size, b"\x00"
)
- data += align_data(new_value + bytes([0xFF]), self.block_size, b"\xFF")
+ data += align_data(new_value + bytes([0xFF]), self.block_size, b"\xff")
if pos + len(data) > consts.NORCOW_SECTOR_SIZE:
raise RuntimeError("Norcow: item too big")
diff --git a/storage/tests/python/src/storage.py b/storage/tests/python/src/storage.py
index ef4f534d..39a3d133 100644
--- a/storage/tests/python/src/storage.py
+++ b/storage/tests/python/src/storage.py
@@ -154,7 +154,7 @@ class Storage:
counter = val.to_bytes(4, sys.byteorder)
if self.nc.is_byte_access():
- counter += bytearray(b"\xFF" * consts.COUNTER_TAIL_SIZE)
+ counter += bytearray(b"\xff" * consts.COUNTER_TAIL_SIZE)
self.set(key, counter)
def next_counter(self, key: int) -> int:
@@ -234,7 +234,7 @@ class Storage:
def _set_encrypt(self, key: int, val: bytes):
# In C, data are preallocated beforehand for encrypted values,
# to match the behaviour we do the same.
- preallocate = b"\xFF" * (
+ preallocate = b"\xff" * (
consts.CHACHA_IV_SIZE + len(val) + consts.POLY1305_MAC_SIZE
)
self.nc.set(key, preallocate)
diff --git a/storage/tests/python/tests/test_helpers.py b/storage/tests/python/tests/test_helpers.py
index 1c8c1e63..c655974b 100644
--- a/storage/tests/python/tests/test_helpers.py
+++ b/storage/tests/python/tests/test_helpers.py
@@ -8,7 +8,7 @@ def test_read_bytes_by_words():
assert n == 0x0102030405060708
assert array == helpers.to_bytes_by_words(n, PIN_LOG_SIZE)[56:]
- array = b"\xFF\xFF\xFF\x01\x01\x05\x09\x01"
+ array = b"\xff\xff\xff\x01\x01\x05\x09\x01"
n = helpers.to_int_by_words(array)
assert n == 0x01FFFFFF01090501
assert array == helpers.to_bytes_by_words(n, PIN_LOG_SIZE)[56:]
diff --git a/storage/tests/python/tests/test_norcow_qw.py b/storage/tests/python/tests/test_norcow_qw.py
index deab8121..ab329b31 100644
--- a/storage/tests/python/tests/test_norcow_qw.py
+++ b/storage/tests/python/tests/test_norcow_qw.py
@@ -43,7 +43,7 @@ def test_norcow_update():
data = n._dump()[0][:256]
assert data[:16] == consts.NORCOW_MAGIC_AND_VERSION + b"\x00" * 8
assert data[16:18] == b"\x01\x00" # app + key
- assert data[18:20] == b"\x0B\x00" # length
+ assert data[18:20] == b"\x0b\x00" # length
assert data[20:31] == b"1234567890A" # data
assert data[31:32] == bytes([0] * 1) # alignment
assert common.all_ff_bytes(data[32:])
@@ -54,7 +54,7 @@ def test_norcow_update():
assert data[16:32] == bytes([0] * 16) # empty data
assert data[32:34] == b"\x01\x00" # app + key
- assert data[34:36] == b"\x0B\x00" # length
+ assert data[34:36] == b"\x0b\x00" # length
assert data[36:47] == b"A0987654321" # data
assert data[47:48] == bytes([0] * 1) # alignment
assert common.all_ff_bytes(data[48:])
@@ -64,7 +64,7 @@ def test_norcow_update():
data = n._dump()[0][:256]
assert data[:16] == consts.NORCOW_MAGIC_AND_VERSION + b"\x00" * 8
assert data[16:18] == b"\x01\x00" # app + key
- assert data[18:20] == b"\x0C\x00" # length
+ assert data[18:20] == b"\x0c\x00" # length
assert data[20:32] == b"1234567890AB" # data
assert common.all_ff_bytes(data[32:])
@@ -74,7 +74,7 @@ def test_norcow_update():
assert data[16:32] == bytes([0] * 16) # empty data
assert data[32:34] == b"\x01\x00" # app + key
- assert data[34:36] == b"\x0C\x00" # length
+ assert data[34:36] == b"\x0c\x00" # length
assert data[36:48] == b"BA0987654321" # data
assert common.all_ff_bytes(data[48:])
@@ -84,19 +84,19 @@ def test_norcow_update():
n.set(0x0102, b"world!_world!")
data = n._dump()[0][:256]
assert data[offset : offset + 2] == b"\x02\x01" # app + key
- assert data[offset + 2 : offset + 4] == b"\x0D\x00" # length
+ assert data[offset + 2 : offset + 4] == b"\x0d\x00" # length
assert data[offset + 16 : offset + 16 + 13] == b"world!_world!" # data
assert data[offset + 16 + 13 : offset + 32] == b"\xff\xff\xff" # alignment
assert common.all_ff_bytes(data[offset + 32 :])
n.set(0x0102, b"hello!_hello!")
data = n._dump()[0][:256]
- assert data[offset : offset + 4] == b"\x02\x01\x0D\x00" # app + key + length
+ assert data[offset : offset + 4] == b"\x02\x01\x0d\x00" # app + key + length
assert data[offset + 4 : offset + 32] == bytes([0] * 28)
offset += 32
- assert data[offset + 0 : offset + 4] == b"\x02\x01\x0D\x00" # app + key + length
+ assert data[offset + 0 : offset + 4] == b"\x02\x01\x0d\x00" # app + key + length
assert data[offset + 4 : offset + 16] == b"\x00" * 12 # alignment
assert data[offset + 16 : offset + 16 + 13] == b"hello!_hello!" # data
assert data[offset + 16 + 13 : offset + 32] == b"\xff\xff\xff" # alignment
@@ -110,7 +110,7 @@ def test_norcow_set_qw_long():
n.set(0x0001, b"1234567890abc")
data = n._dump()[0][:256]
assert data[:16] == consts.NORCOW_MAGIC_AND_VERSION + b"\x00" * 8
- assert data[16:20] == b"\x01\x00\x0D\x00" # app + key + length
+ assert data[16:20] == b"\x01\x00\x0d\x00" # app + key + length
assert data[32:45] == b"1234567890abc" # data
assert common.all_ff_bytes(data[45:])
@@ -118,14 +118,14 @@ def test_norcow_set_qw_long():
n.set(0x0901, b"hello_hello__")
data = n._dump()[0][:256]
assert data[:16] == consts.NORCOW_MAGIC_AND_VERSION + b"\x00" * 8
- assert data[16:20] == b"\x01\x09\x0D\x00" # app + key + length
+ assert data[16:20] == b"\x01\x09\x0d\x00" # app + key + length
assert data[32:45] == b"hello_hello__" # data
assert common.all_ff_bytes(data[45:])
offset = 48
n.set(0x0102, b"world!_world!")
data = n._dump()[0][:256]
- assert data[offset : offset + 4] == b"\x02\x01\x0D\x00" # app + key + length
+ assert data[offset : offset + 4] == b"\x02\x01\x0d\x00" # app + key + length
assert data[offset + 16 : offset + 16 + 13] == b"world!_world!" # data
assert data[offset + 16 + 13 : offset + 32] == b"\xff\xff\xff" # alignment
assert common.all_ff_bytes(data[offset + 32 :])
diff --git a/storage/tests/tests/test_pin.py b/storage/tests/tests/test_pin.py
index bea1dbbd..ac5247a8 100644
--- a/storage/tests/tests/test_pin.py
+++ b/storage/tests/tests/test_pin.py
@@ -11,7 +11,7 @@ def test_init_pin(nc_class):
sc, sp = common.init(nc_class, uid=b"\x00\x00\x00\x00\x00\x00")
assert common.memory_equals(sc, sp)
- sc, sp = common.init(nc_class, uid=b"\x22\x00\xDD\x00\x00\xBE")
+ sc, sp = common.init(nc_class, uid=b"\x22\x00\xdd\x00\x00\xbe")
assert common.memory_equals(sc, sp)
diff --git a/storage/tests/tests/test_set_get.py b/storage/tests/tests/test_set_get.py
index 25838d61..f98f88cc 100644
--- a/storage/tests/tests/test_set_get.py
+++ b/storage/tests/tests/test_set_get.py
@@ -48,18 +48,18 @@ def test_set_equal(nc_class):
def test_set_over_ff(nc_class):
sc, sp = common.init(nc_class, unlock=True)
for s in (sc, sp):
- s.set(0xFF01, b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF")
+ s.set(0xFF01, b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff")
s.set(0xFF01, b"0123456789A")
- s.set(0xFF02, b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF")
+ s.set(0xFF02, b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff")
s.set(0xFF02, b"0123456789AB")
- s.set(0xFF03, b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF")
+ s.set(0xFF03, b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff")
s.set(0xFF03, b"0123456789ABC")
- s.set(0xFF04, b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF")
+ s.set(0xFF04, b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff")
s.set(0xFF04, b"0123456789ABCD")
- s.set(0xFF05, b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF")
+ s.set(0xFF05, b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff")
s.set(0xFF05, b"0123456789ABCDE")
s.set(
- 0xFF06, b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
+ 0xFF06, b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
)
s.set(0xFF06, b"0123456789ABCDEF")
diff --git a/tests/device_tests/bitcoin/test_signtx.py b/tests/device_tests/bitcoin/test_signtx.py
index ef5d51e1..a3136e13 100644
--- a/tests/device_tests/bitcoin/test_signtx.py
+++ b/tests/device_tests/bitcoin/test_signtx.py
@@ -870,8 +870,9 @@ def test_attack_change_outputs(session: Session):
return msg
- with client, pytest.raises(
- TrezorFailure, match="Transaction has changed during signing"
+ with (
+ client,
+ pytest.raises(TrezorFailure, match="Transaction has changed during signing"),
):
# Set up attack processors
client.set_filter(messages.TxAck, attack_processor)
@@ -925,8 +926,9 @@ def test_attack_modify_change_address(session: Session):
return msg
- with session.client as client, pytest.raises(
- TrezorFailure, match="Transaction has changed during signing"
+ with (
+ session.client as client,
+ pytest.raises(TrezorFailure, match="Transaction has changed during signing"),
):
# Set up attack processors
client.set_filter(messages.TxAck, attack_processor)
diff --git a/tests/device_tests/ethereum/test_sign_typed_data.py b/tests/device_tests/ethereum/test_sign_typed_data.py
index 0892fa11..7e45d956 100644
--- a/tests/device_tests/ethereum/test_sign_typed_data.py
+++ b/tests/device_tests/ethereum/test_sign_typed_data.py
@@ -130,8 +130,9 @@ def test_ethereum_sign_typed_data_cancel(session: Session):
@pytest.mark.models("core")
def test_ethereum_sign_typed_data_bad_show_message_hash(session: Session):
- with session.client, pytest.raises(
- exceptions.TrezorFailure, match="Message hash mismatch"
+ with (
+ session.client,
+ pytest.raises(exceptions.TrezorFailure, match="Message hash mismatch"),
):
ethereum.sign_typed_data(
session,
diff --git a/tests/device_tests/reset_recovery/test_recovery_slip39_advanced_dryrun.py b/tests/device_tests/reset_recovery/test_recovery_slip39_advanced_dryrun.py
index 76449510..9057bdd3 100644
--- a/tests/device_tests/reset_recovery/test_recovery_slip39_advanced_dryrun.py
+++ b/tests/device_tests/reset_recovery/test_recovery_slip39_advanced_dryrun.py
@@ -57,8 +57,11 @@ def test_2of3_dryrun(session: Session):
@pytest.mark.setup_client(mnemonic=MNEMONIC_SLIP39_ADVANCED_20)
def test_2of3_invalid_seed_dryrun(session: Session):
# test fails because of different seed on device
- with session.client as client, pytest.raises(
- TrezorFailure, match=r"The seed does not match the one in the device"
+ with (
+ session.client as client,
+ pytest.raises(
+ TrezorFailure, match=r"The seed does not match the one in the device"
+ ),
):
IF = InputFlowSlip39AdvancedRecoveryDryRun(
session.client, INVALID_SHARES_SLIP39_ADVANCED_20, mismatch=True
diff --git a/tests/device_tests/reset_recovery/test_recovery_slip39_basic_dryrun.py b/tests/device_tests/reset_recovery/test_recovery_slip39_basic_dryrun.py
index e40d8ee4..fc7b72d8 100644
--- a/tests/device_tests/reset_recovery/test_recovery_slip39_basic_dryrun.py
+++ b/tests/device_tests/reset_recovery/test_recovery_slip39_basic_dryrun.py
@@ -53,8 +53,11 @@ def test_2of3_dryrun(session: Session):
@pytest.mark.setup_client(mnemonic=SHARES_20_2of3[0:2])
def test_2of3_invalid_seed_dryrun(session: Session):
# test fails because of different seed on device
- with session.client as client, pytest.raises(
- TrezorFailure, match=r"The seed does not match the one in the device"
+ with (
+ session.client as client,
+ pytest.raises(
+ TrezorFailure, match=r"The seed does not match the one in the device"
+ ),
):
IF = InputFlowSlip39BasicRecoveryDryRun(
session.client, INVALID_SHARES_20_2of3, mismatch=True
diff --git a/tests/device_tests/test_language.py b/tests/device_tests/test_language.py
index e45776d1..d3374823 100644
--- a/tests/device_tests/test_language.py
+++ b/tests/device_tests/test_language.py
@@ -108,9 +108,10 @@ def test_error_too_long(session: Session):
# Translations too long
# Sending more than allowed by the flash capacity
max_length = MAX_DATA_LENGTH[session.model]
- with pytest.raises(
- exceptions.TrezorFailure, match="Translations too long"
- ), session.client:
+ with (
+ pytest.raises(exceptions.TrezorFailure, match="Translations too long"),
+ session.client,
+ ):
bad_data = (max_length + 1) * b"a"
device.change_language(session, language_data=bad_data)
assert session.features.language == "en-US"
@@ -123,9 +124,10 @@ def test_error_invalid_data_length(session: Session):
assert session.features.language == "en-US"
# Invalid data length
# Sending more data than advertised in the header
- with pytest.raises(
- exceptions.TrezorFailure, match="Invalid data length"
- ), session.client:
+ with (
+ pytest.raises(exceptions.TrezorFailure, match="Invalid data length"),
+ session.client,
+ ):
good_data = build_and_sign_blob("cs", session)
bad_data = good_data + b"abcd"
device.change_language(session, language_data=bad_data)
@@ -139,9 +141,10 @@ def test_error_invalid_header_magic(session: Session):
assert session.features.language == "en-US"
# Invalid header magic
# Does not match the expected magic
- with pytest.raises(
- exceptions.TrezorFailure, match="Invalid translations data"
- ), session.client:
+ with (
+ pytest.raises(exceptions.TrezorFailure, match="Invalid translations data"),
+ session.client,
+ ):
good_data = build_and_sign_blob("cs", session)
bad_data = 4 * b"a" + good_data[4:]
device.change_language(session, language_data=bad_data)
@@ -155,9 +158,12 @@ def test_error_invalid_data_hash(session: Session):
assert session.features.language == "en-US"
# Invalid data hash
# Changing the data after their hash has been calculated
- with pytest.raises(
- exceptions.TrezorFailure, match="Translation data verification failed"
- ), session.client:
+ with (
+ pytest.raises(
+ exceptions.TrezorFailure, match="Translation data verification failed"
+ ),
+ session.client,
+ ):
good_data = build_and_sign_blob("cs", session)
bad_data = good_data[:-8] + 8 * b"a"
device.change_language(
@@ -174,9 +180,10 @@ def test_error_version_mismatch(session: Session):
assert session.features.language == "en-US"
# Translations version mismatch
# Change the version to one not matching the current device
- with pytest.raises(
- exceptions.TrezorFailure, match="Translations version mismatch"
- ), session.client:
+ with (
+ pytest.raises(exceptions.TrezorFailure, match="Translations version mismatch"),
+ session.client,
+ ):
blob = prepare_blob("cs", session.model, (3, 5, 4, 0))
device.change_language(
session,
@@ -192,9 +199,10 @@ def test_error_invalid_signature(session: Session):
assert session.features.language == "en-US"
# Invalid signature
# Changing the data in the signature section
- with pytest.raises(
- exceptions.TrezorFailure, match="Invalid translations data"
- ), session.client:
+ with (
+ pytest.raises(exceptions.TrezorFailure, match="Invalid translations data"),
+ session.client,
+ ):
blob = prepare_blob("cs", session.model, session.version)
blob.proof = translations.Proof(
merkle_proof=[],
diff --git a/tests/device_tests/test_msg_applysettings.py b/tests/device_tests/test_msg_applysettings.py
index 5281f5c7..f43eb978 100644
--- a/tests/device_tests/test_msg_applysettings.py
+++ b/tests/device_tests/test_msg_applysettings.py
@@ -390,9 +390,10 @@ def test_safety_checks(session: Session):
assert session.features.safety_checks == messages.SafetyCheckLevel.Strict
- with pytest.raises(
- exceptions.TrezorFailure, match="Forbidden key path"
- ), session.client as client:
+ with (
+ pytest.raises(exceptions.TrezorFailure, match="Forbidden key path"),
+ session.client as client,
+ ):
client.set_expected_responses([messages.Failure])
get_bad_address()
@@ -419,9 +420,10 @@ def test_safety_checks(session: Session):
assert session.features.safety_checks == messages.SafetyCheckLevel.Strict
- with pytest.raises(
- exceptions.TrezorFailure, match="Forbidden key path"
- ), session.client as client:
+ with (
+ pytest.raises(exceptions.TrezorFailure, match="Forbidden key path"),
+ session.client as client,
+ ):
client.set_expected_responses([messages.Failure])
get_bad_address()
@@ -459,9 +461,10 @@ def test_experimental_features(session: Session):
assert not session.features.experimental_features
- with pytest.raises(
- exceptions.TrezorFailure, match="DataError"
- ), session.client as client:
+ with (
+ pytest.raises(exceptions.TrezorFailure, match="DataError"),
+ session.client as client,
+ ):
client.set_expected_responses([messages.Failure])
experimental_call()
diff --git a/tests/upgrade_tests/__init__.py b/tests/upgrade_tests/__init__.py
index be9fb9fe..6291ca71 100644
--- a/tests/upgrade_tests/__init__.py
+++ b/tests/upgrade_tests/__init__.py
@@ -60,7 +60,7 @@ def version_from_tag(tag: str | None) -> tuple | None:
def for_all(
*args: str,
legacy_minimum_version: Tuple[int, int, int] = (1, 0, 0),
- core_minimum_version: Tuple[int, int, int] = (2, 0, 0)
+ core_minimum_version: Tuple[int, int, int] = (2, 0, 0),
) -> "MarkDecorator":
"""Parametrizing decorator for test cases.
diff --git a/tests/upgrade_tests/test_firmware_upgrades.py b/tests/upgrade_tests/test_firmware_upgrades.py
index 1c5918e9..40800844 100644
--- a/tests/upgrade_tests/test_firmware_upgrades.py
+++ b/tests/upgrade_tests/test_firmware_upgrades.py
@@ -368,9 +368,10 @@ def test_upgrade_reset_no_backup(gen: str, tag: str):
@for_all("core", core_minimum_version=(2, 1, 9))
@lower_models_minimum_version
def test_upgrade_shamir_recovery(gen: str, tag: Optional[str]):
- with EmulatorWrapper(gen, tag) as emu, BackgroundDeviceHandler(
- emu.client
- ) as device_handler:
+ with (
+ EmulatorWrapper(gen, tag) as emu,
+ BackgroundDeviceHandler(emu.client) as device_handler,
+ ):
assert emu.client.features.recovery_status == RecoveryStatus.Nothing
emu.client.watch_layout(True)
debug = device_handler.debuglink()
diff --git a/tools/changelog.py b/tools/changelog.py
index 6c91d322..bc957d20 100755
--- a/tools/changelog.py
+++ b/tools/changelog.py
@@ -131,9 +131,10 @@ def filter_changelog(changelog_file: Path, internal_name: str):
return None
destination_file = changelog_file.with_suffix(f".{internal_name}.md")
- with open(changelog_file, "r") as changelog, open(
- destination_file, "w"
- ) as destination:
+ with (
+ open(changelog_file, "r") as changelog,
+ open(destination_file, "w") as destination,
+ ):
for line in changelog:
res = filter_line(line)
if res is not None:
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.