1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 23:08:14 +00:00

style(core): mypy: disable implicit Optional for function arguments

https://www.python.org/dev/peps/pep-0484/#union-types
This commit is contained in:
Martin Milata 2021-03-17 21:02:02 +01:00 committed by matejcik
parent bb30f5026c
commit 8b3ac659a0
44 changed files with 157 additions and 106 deletions

View File

@ -47,7 +47,7 @@ STATIC secbool wrapped_ui_wait_callback(uint32_t wait, uint32_t progress,
}
/// def init(
/// ui_wait_callback: Callable[[int, int, str], bool] = None
/// ui_wait_callback: Optional[Callable[[int, int, str], bool]] = None
/// ) -> None:
/// """
/// Initializes the storage. Must be called before any other method is

View File

@ -49,7 +49,12 @@ typedef struct _mp_obj_AES_t {
uint8_t iv[AES_BLOCK_SIZE];
} mp_obj_AES_t;
/// def __init__(self, mode: int, key: bytes, iv: bytes = None) -> None:
/// def __init__(
/// self,
/// mode: int,
/// key: bytes,
/// iv: Optional[bytes] = None,
/// ) -> None:
/// """
/// Initialize AES context.
/// """

View File

@ -49,9 +49,9 @@ STATIC const mp_obj_type_t mod_trezorcrypto_HDNode_type;
/// fingerprint: int,
/// child_num: int,
/// chain_code: bytes,
/// private_key: bytes = None,
/// public_key: bytes = None,
/// curve_name: str = None,
/// private_key: Optional[bytes] = None,
/// public_key: Optional[bytes] = None,
/// curve_name: Optional[str] = None,
/// ) -> None:
/// """
/// """

View File

@ -125,7 +125,7 @@ STATIC void wrapped_ui_wait_callback(uint32_t current, uint32_t total) {
/// def seed(
/// mnemonic: str,
/// passphrase: str,
/// callback: Callable[[int, int], None] = None,
/// callback: Optional[Callable[[int, int], None]] = None,
/// ) -> bytes:
/// """
/// Generate seed from mnemonic and passphrase.

View File

@ -37,7 +37,7 @@ typedef struct _mp_obj_Blake256_t {
STATIC mp_obj_t mod_trezorcrypto_Blake256_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None) -> None:
/// def __init__(self, data: Optional[bytes] = None) -> None:
/// """
/// Creates a hash context object.
/// """

View File

@ -41,10 +41,10 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2b_update(mp_obj_t self, mp_obj_t data);
/// def __init__(
/// self,
/// data: bytes = None,
/// data: Optional[bytes] = None,
/// outlen: int = blake2b.digest_size,
/// key: bytes = None,
/// personal: bytes = None,
/// key: Optional[bytes] = None,
/// personal: Optional[bytes] = None,
/// ) -> None:
/// """
/// Creates a hash context object.

View File

@ -41,10 +41,10 @@ STATIC mp_obj_t mod_trezorcrypto_Blake2s_update(mp_obj_t self, mp_obj_t data);
/// def __init__(
/// self,
/// data: bytes = None,
/// data: Optional[bytes] = None,
/// outlen: int = blake2s.digest_size,
/// key: bytes = None,
/// personal: bytes = None,
/// key: Optional[bytes] = None,
/// personal: Optional[bytes] = None,
/// ) -> None:
/// """
/// Creates a hash context object.

View File

@ -41,7 +41,7 @@ typedef struct _mp_obj_Groestl512_t {
STATIC mp_obj_t mod_trezorcrypto_Groestl512_update(mp_obj_t self,
mp_obj_t data);
/// def __init__(self, data: bytes = None) -> None:
/// def __init__(self, data: Optional[bytes] = None) -> None:
/// """
/// Creates a hash context object.
/// """

View File

@ -48,7 +48,7 @@ STATIC mp_obj_t mod_trezorcrypto_Hmac_update(mp_obj_t self, mp_obj_t data);
/// self,
/// hashtype: int,
/// key: bytes,
/// message: bytes = None
/// message: Optional[bytes] = None,
/// ) -> None:
/// """
/// Create a HMAC context.

View File

@ -49,7 +49,7 @@ STATIC mp_obj_t mod_trezorcrypto_Pbkdf2_update(mp_obj_t self, mp_obj_t data);
/// prf: int,
/// password: bytes,
/// salt: bytes,
/// iterations: int = None,
/// iterations: Optional[int] = None,
/// blocknr: int = 1,
/// ) -> None:
/// """

View File

@ -37,7 +37,7 @@ typedef struct _mp_obj_Ripemd160_t {
STATIC mp_obj_t mod_trezorcrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None) -> None:
/// def __init__(self, data: Optional[bytes] = None) -> None:
/// """
/// Creates a hash context object.
/// """

View File

@ -113,7 +113,7 @@ enum {
/// secret_key: bytes,
/// digest: bytes,
/// compressed: bool = True,
/// canonical: int = None,
/// canonical: Optional[int] = None,
/// ) -> bytes:
/// """
/// Uses secret key to produce the signature of the digest.

View File

@ -37,7 +37,7 @@ typedef struct _mp_obj_Sha1_t {
STATIC mp_obj_t mod_trezorcrypto_Sha1_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None) -> None:
/// def __init__(self, data: Optional[bytes] = None) -> None:
/// """
/// Creates a hash context object.
/// """

View File

@ -37,7 +37,7 @@ typedef struct _mp_obj_Sha256_t {
STATIC mp_obj_t mod_trezorcrypto_Sha256_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None) -> None:
/// def __init__(self, data: Optional[bytes] = None) -> None:
/// """
/// Creates a hash context object.
/// """

View File

@ -38,7 +38,11 @@ typedef struct _mp_obj_Sha3_256_t {
STATIC mp_obj_t mod_trezorcrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None, keccak: bool = False) -> None:
/// def __init__(
/// self,
/// data: Optional[bytes] = None,
/// keccak: bool = False,
/// ) -> None:
/// """
/// Creates a hash context object.
/// """

View File

@ -38,7 +38,11 @@ typedef struct _mp_obj_Sha3_512_t {
STATIC mp_obj_t mod_trezorcrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None, keccak: bool = False) -> None:
/// def __init__(
/// self,
/// data: Optional[bytes] = None,
/// keccak: bool = False,
/// ) -> None:
/// """
/// Creates a hash context object.
/// """

View File

@ -37,7 +37,7 @@ typedef struct _mp_obj_Sha512_t {
STATIC mp_obj_t mod_trezorcrypto_Sha512_update(mp_obj_t self, mp_obj_t data);
/// def __init__(self, data: bytes = None) -> None:
/// def __init__(self, data: Optional[bytes] = None) -> None:
/// """
/// Creates a hash context object.
/// """

View File

@ -93,8 +93,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_bar_obj, 6, 6,
/// w: int,
/// h: int,
/// fgcolor: int,
/// bgcolor: int = None,
/// radius: int = None,
/// bgcolor: Optional[int] = None,
/// radius: Optional[int] = None,
/// ) -> None:
/// """
/// Renders a rounded bar at position (x,y = upper left corner) with width w
@ -243,8 +243,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_icon_obj, 6, 6,
/// yoffset: int,
/// fgcolor: int,
/// bgcolor: int,
/// icon: bytes = None,
/// iconfgcolor: int = None,
/// icon: Optional[bytes] = None,
/// iconfgcolor: Optional[int] = None,
/// ) -> None:
/// """
/// Renders a rotating loader graphic.
@ -317,8 +317,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorui_Display_print_obj,
/// font: int,
/// fgcolor: int,
/// bgcolor: int,
/// text_offset: int = None,
/// text_len: int = None,
/// text_offset: Optional[int] = None,
/// text_len: Optional[int] = None,
/// ) -> None:
/// """
/// Renders left-aligned text at position (x,y) where x is left position and
@ -421,8 +421,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_right_obj,
/// self,
/// text: str,
/// font: int,
/// text_offset: int = None,
/// text_len: int = None,
/// text_offset: Optional[int] = None,
/// text_len: Optional[int] = None,
/// ) -> int:
/// """
/// Returns a width of text in pixels. Font font is used for rendering.
@ -499,7 +499,7 @@ STATIC mp_obj_t mod_trezorui_Display_qrcode(size_t n_args,
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_qrcode_obj, 5,
5, mod_trezorui_Display_qrcode);
/// def orientation(self, degrees: int = None) -> int:
/// def orientation(self, degrees: Optional[int] = None) -> int:
/// """
/// Sets display orientation to 0, 90, 180 or 270 degrees.
/// Everything needs to be redrawn again when this function is used.
@ -524,7 +524,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_orientation_obj,
1, 2,
mod_trezorui_Display_orientation);
/// def backlight(self, val: int = None) -> int:
/// def backlight(self, val: Optional[int] = None) -> int:
/// """
/// Sets backlight intensity to the value specified in val.
/// Call without the val parameter to just perform the read of the value.
@ -547,7 +547,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_backlight_obj,
1, 2,
mod_trezorui_Display_backlight);
/// def offset(self, xy: Tuple[int, int] = None) -> Tuple[int, int]:
/// def offset(self, xy: Optional[Tuple[int, int]] = None) -> Tuple[int, int]:
/// """
/// Sets offset (x, y) for all subsequent drawing calls.
/// Call without the xy parameter to just perform the read of the value.

View File

@ -62,7 +62,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorutils_consteq_obj,
/// dst_ofs: int,
/// src: bytes,
/// src_ofs: int,
/// n: int = None,
/// n: Optional[int] = None,
/// ) -> int:
/// """
/// Copies at most `n` bytes from `src` at offset `src_ofs` to
@ -99,7 +99,7 @@ STATIC mp_obj_t mod_trezorutils_memcpy(size_t n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorutils_memcpy_obj, 4, 5,
mod_trezorutils_memcpy);
/// def halt(msg: str = None) -> None:
/// def halt(msg: Optional[str] = None) -> None:
/// """
/// Halts execution.
/// """

View File

@ -3,7 +3,7 @@ from typing import *
# extmod/modtrezorconfig/modtrezorconfig.c
def init(
ui_wait_callback: Callable[[int, int, str], bool] = None
ui_wait_callback: Optional[Callable[[int, int, str], bool]] = None
) -> None:
"""
Initializes the storage. Must be called before any other method is

View File

@ -12,7 +12,12 @@ class aes:
OFB: int
CTR: int
def __init__(self, mode: int, key: bytes, iv: bytes = None) -> None:
def __init__(
self,
mode: int,
key: bytes,
iv: Optional[bytes] = None,
) -> None:
"""
Initialize AES context.
"""
@ -36,7 +41,7 @@ class blake256:
block_size: int
digest_size: int
def __init__(self, data: bytes = None) -> None:
def __init__(self, data: Optional[bytes] = None) -> None:
"""
Creates a hash context object.
"""
@ -62,10 +67,10 @@ class blake2b:
def __init__(
self,
data: bytes = None,
data: Optional[bytes] = None,
outlen: int = blake2b.digest_size,
key: bytes = None,
personal: bytes = None,
key: Optional[bytes] = None,
personal: Optional[bytes] = None,
) -> None:
"""
Creates a hash context object.
@ -92,10 +97,10 @@ class blake2s:
def __init__(
self,
data: bytes = None,
data: Optional[bytes] = None,
outlen: int = blake2s.digest_size,
key: bytes = None,
personal: bytes = None,
key: Optional[bytes] = None,
personal: Optional[bytes] = None,
) -> None:
"""
Creates a hash context object.
@ -157,7 +162,7 @@ class groestl512:
block_size: int
digest_size: int
def __init__(self, data: bytes = None) -> None:
def __init__(self, data: Optional[bytes] = None) -> None:
"""
Creates a hash context object.
"""
@ -185,7 +190,7 @@ class hmac:
self,
hashtype: int,
key: bytes,
message: bytes = None
message: Optional[bytes] = None,
) -> None:
"""
Create a HMAC context.
@ -215,7 +220,7 @@ class pbkdf2:
prf: int,
password: bytes,
salt: bytes,
iterations: int = None,
iterations: Optional[int] = None,
blocknr: int = 1,
) -> None:
"""
@ -241,7 +246,7 @@ class ripemd160:
block_size: int
digest_size: int
def __init__(self, data: bytes = None) -> None:
def __init__(self, data: Optional[bytes] = None) -> None:
"""
Creates a hash context object.
"""
@ -265,7 +270,7 @@ class sha1:
block_size: int
digest_size: int
def __init__(self, data: bytes = None) -> None:
def __init__(self, data: Optional[bytes] = None) -> None:
"""
Creates a hash context object.
"""
@ -289,7 +294,7 @@ class sha256:
block_size: int
digest_size: int
def __init__(self, data: bytes = None) -> None:
def __init__(self, data: Optional[bytes] = None) -> None:
"""
Creates a hash context object.
"""
@ -313,7 +318,11 @@ class sha3_256:
block_size: int
digest_size: int
def __init__(self, data: bytes = None, keccak: bool = False) -> None:
def __init__(
self,
data: Optional[bytes] = None,
keccak: bool = False,
) -> None:
"""
Creates a hash context object.
"""
@ -342,7 +351,11 @@ class sha3_512:
block_size: int
digest_size: int
def __init__(self, data: bytes = None, keccak: bool = False) -> None:
def __init__(
self,
data: Optional[bytes] = None,
keccak: bool = False,
) -> None:
"""
Creates a hash context object.
"""
@ -371,7 +384,7 @@ class sha512:
block_size: int
digest_size: int
def __init__(self, data: bytes = None) -> None:
def __init__(self, data: Optional[bytes] = None) -> None:
"""
Creates a hash context object.
"""

View File

@ -13,9 +13,9 @@ class HDNode:
fingerprint: int,
child_num: int,
chain_code: bytes,
private_key: bytes = None,
public_key: bytes = None,
curve_name: str = None,
private_key: Optional[bytes] = None,
public_key: Optional[bytes] = None,
curve_name: Optional[str] = None,
) -> None:
"""
"""

View File

@ -42,7 +42,7 @@ def check(mnemonic: str) -> bool:
def seed(
mnemonic: str,
passphrase: str,
callback: Callable[[int, int], None] = None,
callback: Optional[Callable[[int, int], None]] = None,
) -> bytes:
"""
Generate seed from mnemonic and passphrase.

View File

@ -22,7 +22,7 @@ def sign(
secret_key: bytes,
digest: bytes,
compressed: bool = True,
canonical: int = None,
canonical: Optional[int] = None,
) -> bytes:
"""
Uses secret key to produce the signature of the digest.

View File

@ -40,8 +40,8 @@ class Display:
w: int,
h: int,
fgcolor: int,
bgcolor: int = None,
radius: int = None,
bgcolor: Optional[int] = None,
radius: Optional[int] = None,
) -> None:
"""
Renders a rounded bar at position (x,y = upper left corner) with width w
@ -89,8 +89,8 @@ class Display:
yoffset: int,
fgcolor: int,
bgcolor: int,
icon: bytes = None,
iconfgcolor: int = None,
icon: Optional[bytes] = None,
iconfgcolor: Optional[int] = None,
) -> None:
"""
Renders a rotating loader graphic.
@ -114,8 +114,8 @@ class Display:
font: int,
fgcolor: int,
bgcolor: int,
text_offset: int = None,
text_len: int = None,
text_offset: Optional[int] = None,
text_len: Optional[int] = None,
) -> None:
"""
Renders left-aligned text at position (x,y) where x is left position and
@ -159,8 +159,8 @@ class Display:
self,
text: str,
font: int,
text_offset: int = None,
text_len: int = None,
text_offset: Optional[int] = None,
text_len: Optional[int] = None,
) -> int:
"""
Returns a width of text in pixels. Font font is used for rendering.
@ -181,7 +181,7 @@ class Display:
Scale determines a zoom factor.
"""
def orientation(self, degrees: int = None) -> int:
def orientation(self, degrees: Optional[int] = None) -> int:
"""
Sets display orientation to 0, 90, 180 or 270 degrees.
Everything needs to be redrawn again when this function is used.
@ -189,13 +189,13 @@ class Display:
value.
"""
def backlight(self, val: int = None) -> int:
def backlight(self, val: Optional[int] = None) -> int:
"""
Sets backlight intensity to the value specified in val.
Call without the val parameter to just perform the read of the value.
"""
def offset(self, xy: Tuple[int, int] = None) -> Tuple[int, int]:
def offset(self, xy: Optional[Tuple[int, int]] = None) -> Tuple[int, int]:
"""
Sets offset (x, y) for all subsequent drawing calls.
Call without the xy parameter to just perform the read of the value.

View File

@ -17,7 +17,7 @@ def memcpy(
dst_ofs: int,
src: bytes,
src_ofs: int,
n: int = None,
n: Optional[int] = None,
) -> int:
"""
Copies at most `n` bytes from `src` at offset `src_ofs` to
@ -28,7 +28,7 @@ def memcpy(
# extmod/modtrezorutils/modtrezorutils.c
def halt(msg: str = None) -> None:
def halt(msg: Optional[str] = None) -> None:
"""
Halts execution.
"""

View File

@ -12,7 +12,7 @@ from .multisig import multisig_get_pubkeys, multisig_pubkey_index
from .scripts import output_script_multisig, output_script_native_p2wpkh_or_p2wsh
if False:
from typing import List
from typing import List, Optional
from trezor.crypto import bip32
from trezor.messages.TxInputType import EnumTypeInputScriptType
@ -21,7 +21,7 @@ def get_address(
script_type: EnumTypeInputScriptType,
coin: CoinInfo,
node: bip32.HDNode,
multisig: MultisigRedeemScriptType = None,
multisig: Optional[MultisigRedeemScriptType] = None,
) -> str:
if multisig:
# Ensure that our public key is included in the multisig.

View File

@ -63,9 +63,9 @@ PATTERN_UNCHAINED_DEPRECATED = "m/45'/coin_type'/account'/[0-1000000]/address_in
def validate_path_against_script_type(
coin: coininfo.CoinInfo,
msg: MsgWithAddressScriptType = None,
address_n: Bip32Path = None,
script_type: EnumTypeInputScriptType = None,
msg: Optional[MsgWithAddressScriptType] = None,
address_n: Optional[Bip32Path] = None,
script_type: Optional[EnumTypeInputScriptType] = None,
multisig: bool = False,
) -> bool:
patterns = []

View File

@ -252,7 +252,7 @@ def confirm_nondefault_locktime(lock_time: int, lock_time_disabled: bool) -> Awa
return (yield UiConfirmNonDefaultLocktime(lock_time, lock_time_disabled))
def request_tx_meta(tx_req: TxRequest, coin: CoinInfo, tx_hash: bytes = None) -> Awaitable[PrevTx]: # type: ignore
def request_tx_meta(tx_req: TxRequest, coin: CoinInfo, tx_hash: Optional[bytes] = None) -> Awaitable[PrevTx]: # type: ignore
assert tx_req.details is not None
tx_req.request_type = TXMETA
tx_req.details.tx_hash = tx_hash
@ -262,7 +262,7 @@ def request_tx_meta(tx_req: TxRequest, coin: CoinInfo, tx_hash: bytes = None) ->
def request_tx_extra_data( # type: ignore
tx_req: TxRequest, offset: int, size: int, tx_hash: bytes = None
tx_req: TxRequest, offset: int, size: int, tx_hash: Optional[bytes] = None
) -> Awaitable[bytearray]:
assert tx_req.details is not None
tx_req.request_type = TXEXTRADATA
@ -287,7 +287,7 @@ def request_tx_input(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: Optiona
return sanitize_tx_input(ack.tx.input, coin)
def request_tx_prev_input(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes = None) -> Awaitable[PrevInput]: # type: ignore
def request_tx_prev_input(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: Optional[bytes] = None) -> Awaitable[PrevInput]: # type: ignore
assert tx_req.details is not None
tx_req.request_type = TXINPUT
tx_req.details.request_index = i
@ -310,7 +310,7 @@ def request_tx_output(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: Option
return sanitize_tx_output(ack.tx.output, coin)
def request_tx_prev_output(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes = None) -> Awaitable[PrevOutput]: # type: ignore
def request_tx_prev_output(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: Optional[bytes] = None) -> Awaitable[PrevOutput]: # type: ignore
assert tx_req.details is not None
tx_req.request_type = TXOUTPUT
tx_req.details.request_index = i

View File

@ -399,7 +399,7 @@ async def show_address(
address: str,
address_type: EnumTypeCardanoAddressType,
path: List[int],
network: str = None,
network: Optional[str] = None,
) -> bool:
"""
Custom show_address function is needed because cardano addresses don't

View File

@ -25,7 +25,7 @@ def can_lock_device() -> bool:
async def request_pin(
ctx: wire.GenericContext,
prompt: str = "Enter your PIN",
attempts_remaining: int = None,
attempts_remaining: Optional[int] = None,
allow_cancel: bool = True,
) -> str:
await button_request(ctx, code=ButtonRequestType.PinEntry)

View File

@ -6,6 +6,8 @@ from . import mnemonic
from .passphrase import get as get_passphrase
if False:
from typing import Optional
from .paths import Bip32Path, Slip21Path
@ -15,7 +17,9 @@ class Slip21Node:
https://github.com/satoshilabs/slips/blob/master/slip-0021.md.
"""
def __init__(self, seed: bytes = None, data: bytes = None) -> None:
def __init__(
self, seed: Optional[bytes] = None, data: Optional[bytes] = None
) -> None:
assert seed is None or data is None, "Specify exactly one of: seed, data"
if data is not None:
self.data = data

View File

@ -2,6 +2,8 @@ from trezor.crypto.slip39 import Share
from trezor.messages import BackupType
if False:
from typing import Optional
from trezor.messages.ResetDevice import EnumTypeBackupType
@ -26,7 +28,9 @@ def is_slip39_backup_type(backup_type: EnumTypeBackupType) -> bool:
return backup_type in (BackupType.Slip39_Basic, BackupType.Slip39_Advanced)
def infer_backup_type(is_slip39: bool, share: Share = None) -> EnumTypeBackupType:
def infer_backup_type(
is_slip39: bool, share: Optional[Share] = None
) -> EnumTypeBackupType:
if not is_slip39: # BIP-39
return BackupType.Bip39
elif not share or share.group_count < 1: # invalid parameters

View File

@ -172,7 +172,7 @@ class Bip39Keyboard(ui.Layout):
# Word was confirmed by the user.
raise ui.Result(word)
def edit(self, text: str, button: Button = None, index: int = 0) -> None:
def edit(self, text: str, button: Optional[Button] = None, index: int = 0) -> None:
self.pending_button = button
self.pending_index = index

View File

@ -170,7 +170,7 @@ class Slip39Keyboard(ui.Layout):
# Word was confirmed by the user.
raise ui.Result(word)
def edit(self, button: Button = None, index: int = 0) -> None:
def edit(self, button: Optional[Button] = None, index: int = 0) -> None:
self.pending_button = button
self.pending_index = index

View File

@ -205,7 +205,7 @@ async def show_group_threshold_reached(ctx: wire.GenericContext) -> None:
class RecoveryHomescreen(ui.Component):
def __init__(self, text: str, subtext: str = None):
def __init__(self, text: str, subtext: Optional[str] = None):
super().__init__()
self.text = text
self.subtext = subtext
@ -248,7 +248,7 @@ async def homescreen_dialog(
ctx: wire.GenericContext,
homepage: RecoveryHomescreen,
button_label: str,
info_func: Callable = None,
info_func: Optional[Callable] = None,
) -> None:
while True:
if info_func:

View File

@ -4,7 +4,18 @@ bytes, string, embedded message and repeated fields.
"""
if False:
from typing import Any, Callable, Dict, Iterable, List, Tuple, Type, TypeVar, Union
from typing import (
Any,
Callable,
Dict,
Iterable,
List,
Optional,
Tuple,
Type,
TypeVar,
Union,
)
from typing_extensions import Protocol
class Reader(Protocol):
@ -200,7 +211,7 @@ if False:
def load_message(
reader: Reader,
msg_type: Type[LoadedMessageType],
field_cache: FieldCache = None,
field_cache: Optional[FieldCache] = None,
experimental_enabled: bool = True,
) -> LoadedMessageType:
if field_cache is None:
@ -295,7 +306,7 @@ def load_message(
def dump_message(
writer: Writer, msg: MessageType, field_cache: FieldCache = None
writer: Writer, msg: MessageType, field_cache: Optional[FieldCache] = None
) -> None:
repvalue = [0]
@ -360,7 +371,7 @@ def dump_message(
raise TypeError
def count_message(msg: MessageType, field_cache: FieldCache = None) -> int:
def count_message(msg: MessageType, field_cache: Optional[FieldCache] = None) -> int:
nbytes = 0
repvalue = [0]

View File

@ -41,7 +41,7 @@ def _move_session_ids_queue(session_id: bytes) -> None:
_session_ids.insert(0, session_id)
def start_session(received_session_id: bytes = None) -> bytes:
def start_session(received_session_id: Optional[bytes] = None) -> bytes:
if received_session_id and received_session_id in _session_ids:
session_id = received_session_id
else:

View File

@ -59,8 +59,8 @@ TASK_CLOSED = TaskClosed()
def schedule(
task: Task,
value: Any = None,
deadline: int = None,
finalizer: Finalizer = None,
deadline: Optional[int] = None,
finalizer: Optional[Finalizer] = None,
reschedule: bool = False,
) -> None:
"""
@ -322,7 +322,7 @@ class race(Syscall):
scheduled.append(child_task)
# TODO: document the types here
def exit(self, except_for: Task = None) -> None:
def exit(self, except_for: Optional[Task] = None) -> None:
for task in self.scheduled:
if task != except_for:
close(task)

View File

@ -191,7 +191,9 @@ class PassphraseKeyboard(ui.Layout):
# Timeout occurred, let's just reset the pending marker.
self.edit(self.input.text)
def edit(self, text: str, button: KeyButton = None, index: int = 0) -> None:
def edit(
self, text: str, button: Optional[KeyButton] = None, index: int = 0
) -> None:
if len(text) > self.max_length:
return

View File

@ -3,7 +3,7 @@ from micropython import const
from trezor import io, loop, ui
if False:
from typing import Generator
from typing import Generator, Optional
SWIPE_UP = const(0x01)
SWIPE_DOWN = const(0x02)
@ -18,7 +18,9 @@ _SWIPE_TRESHOLD = const(30)
class Swipe(ui.Component):
def __init__(self, directions: int = SWIPE_ALL, area: ui.Area = None) -> None:
def __init__(
self, directions: int = SWIPE_ALL, area: Optional[ui.Area] = None
) -> None:
super().__init__()
if area is None:
area = (0, 0, ui.WIDTH, ui.HEIGHT)

View File

@ -62,7 +62,7 @@ def unimport_end(mods: Iterable[str]) -> None:
gc.collect()
def ensure(cond: bool, msg: str = None) -> None:
def ensure(cond: bool, msg: Optional[str] = None) -> None:
if not cond:
if msg is None:
raise AssertionError

View File

@ -123,7 +123,7 @@ if False:
def _wrap_protobuf_load(
reader: protobuf.Reader,
expected_type: Type[protobuf.LoadedMessageType],
field_cache: protobuf.FieldCache = None,
field_cache: Optional[protobuf.FieldCache] = None,
) -> protobuf.LoadedMessageType:
try:
return protobuf.load_message(
@ -169,7 +169,7 @@ class Context:
self,
msg: protobuf.MessageType,
expected_type: Type[protobuf.LoadedMessageType],
field_cache: protobuf.FieldCache = None,
field_cache: Optional[protobuf.FieldCache] = None,
) -> protobuf.LoadedMessageType:
await self.write(msg, field_cache)
del msg
@ -189,7 +189,7 @@ class Context:
async def read(
self,
expected_type: Type[protobuf.LoadedMessageType],
field_cache: protobuf.FieldCache = None,
field_cache: Optional[protobuf.FieldCache] = None,
) -> protobuf.LoadedMessageType:
if __debug__:
log.debug(
@ -256,7 +256,9 @@ class Context:
return _wrap_protobuf_load(msg.data, exptype)
async def write(
self, msg: protobuf.MessageType, field_cache: protobuf.FieldCache = None
self,
msg: protobuf.MessageType,
field_cache: Optional[protobuf.FieldCache] = None,
) -> None:
if __debug__:
log.debug(

View File

@ -45,7 +45,7 @@ disallow_untyped_decorators = True
disallow_untyped_defs = True
disallow_incomplete_defs = True
namespace_packages = True
# no_implicit_optional = True
no_implicit_optional = True
warn_redundant_casts = True
warn_return_any = True
warn_unused_configs = True