diff --git a/core/embed/extmod/modtrezorconfig/modtrezorconfig.c b/core/embed/extmod/modtrezorconfig/modtrezorconfig.c index 2031734e4..e56cb2ffa 100644 --- a/core/embed/extmod/modtrezorconfig/modtrezorconfig.c +++ b/core/embed/extmod/modtrezorconfig/modtrezorconfig.c @@ -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 diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-aes.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-aes.h index a9226bfbb..78af6a066 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-aes.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-aes.h @@ -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. /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-bip32.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-bip32.h index d2a554f42..8dd685ade 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-bip32.h @@ -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: /// """ /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-bip39.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-bip39.h index 0ac9c8fc3..3873a6660 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-bip39.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-bip39.h @@ -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. diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake256.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake256.h index 423002562..54b8ec94f 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake256.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake256.h @@ -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. /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h index 4ec0124e2..47d6acadf 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake2b.h @@ -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. diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h index 3a2ca04fc..be99143ae 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-blake2s.h @@ -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. diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-groestl.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-groestl.h index 4fb98f230..6cadb9559 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-groestl.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-groestl.h @@ -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. /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-hmac.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-hmac.h index 598505080..0a4eac8f7 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-hmac.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-hmac.h @@ -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. diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h index 85b2ec633..dd493e943 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-pbkdf2.h @@ -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: /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h index ef8ed13b9..f893e1924 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h @@ -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. /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h index eaa615d1f..5aba55a50 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h @@ -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. diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha1.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha1.h index 36e5a6a7d..841c2222b 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha1.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha1.h @@ -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. /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha256.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha256.h index 762eaaf92..a659eb529 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha256.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha256.h @@ -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. /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h index 69f822790..62bd7e59d 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha3-256.h @@ -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. /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h index 8002beeff..5514b8556 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha3-512.h @@ -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. /// """ diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha512.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha512.h index 5a16fd467..e84501d28 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha512.h +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-sha512.h @@ -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. /// """ diff --git a/core/embed/extmod/modtrezorui/modtrezorui-display.h b/core/embed/extmod/modtrezorui/modtrezorui-display.h index d24100005..b0d7aea47 100644 --- a/core/embed/extmod/modtrezorui/modtrezorui-display.h +++ b/core/embed/extmod/modtrezorui/modtrezorui-display.h @@ -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. diff --git a/core/embed/extmod/modtrezorutils/modtrezorutils.c b/core/embed/extmod/modtrezorutils/modtrezorutils.c index 5537214cd..c5bcadf2b 100644 --- a/core/embed/extmod/modtrezorutils/modtrezorutils.c +++ b/core/embed/extmod/modtrezorutils/modtrezorutils.c @@ -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. /// """ diff --git a/core/mocks/generated/trezorconfig.pyi b/core/mocks/generated/trezorconfig.pyi index 130313732..de53e202e 100644 --- a/core/mocks/generated/trezorconfig.pyi +++ b/core/mocks/generated/trezorconfig.pyi @@ -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 diff --git a/core/mocks/generated/trezorcrypto/__init__.pyi b/core/mocks/generated/trezorcrypto/__init__.pyi index 68e270628..ff5f3c228 100644 --- a/core/mocks/generated/trezorcrypto/__init__.pyi +++ b/core/mocks/generated/trezorcrypto/__init__.pyi @@ -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. """ diff --git a/core/mocks/generated/trezorcrypto/bip32.pyi b/core/mocks/generated/trezorcrypto/bip32.pyi index 84a116681..a1d3b54c6 100644 --- a/core/mocks/generated/trezorcrypto/bip32.pyi +++ b/core/mocks/generated/trezorcrypto/bip32.pyi @@ -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: """ """ diff --git a/core/mocks/generated/trezorcrypto/bip39.pyi b/core/mocks/generated/trezorcrypto/bip39.pyi index 1297f8779..615697fd9 100644 --- a/core/mocks/generated/trezorcrypto/bip39.pyi +++ b/core/mocks/generated/trezorcrypto/bip39.pyi @@ -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. diff --git a/core/mocks/generated/trezorcrypto/secp256k1.pyi b/core/mocks/generated/trezorcrypto/secp256k1.pyi index d1f4bdfd2..1a86c6590 100644 --- a/core/mocks/generated/trezorcrypto/secp256k1.pyi +++ b/core/mocks/generated/trezorcrypto/secp256k1.pyi @@ -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. diff --git a/core/mocks/generated/trezorui.pyi b/core/mocks/generated/trezorui.pyi index c0752f309..e78703ce6 100644 --- a/core/mocks/generated/trezorui.pyi +++ b/core/mocks/generated/trezorui.pyi @@ -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. diff --git a/core/mocks/generated/trezorutils.pyi b/core/mocks/generated/trezorutils.pyi index e89fb601f..cde11f30f 100644 --- a/core/mocks/generated/trezorutils.pyi +++ b/core/mocks/generated/trezorutils.pyi @@ -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. """ diff --git a/core/src/apps/bitcoin/addresses.py b/core/src/apps/bitcoin/addresses.py index 50f2569db..364d7bb7e 100644 --- a/core/src/apps/bitcoin/addresses.py +++ b/core/src/apps/bitcoin/addresses.py @@ -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. diff --git a/core/src/apps/bitcoin/keychain.py b/core/src/apps/bitcoin/keychain.py index 9ef791931..2b9a1006b 100644 --- a/core/src/apps/bitcoin/keychain.py +++ b/core/src/apps/bitcoin/keychain.py @@ -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 = [] diff --git a/core/src/apps/bitcoin/sign_tx/helpers.py b/core/src/apps/bitcoin/sign_tx/helpers.py index a56257a46..0dbd1a05e 100644 --- a/core/src/apps/bitcoin/sign_tx/helpers.py +++ b/core/src/apps/bitcoin/sign_tx/helpers.py @@ -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 diff --git a/core/src/apps/cardano/layout.py b/core/src/apps/cardano/layout.py index 73cfebede..dba1a698b 100644 --- a/core/src/apps/cardano/layout.py +++ b/core/src/apps/cardano/layout.py @@ -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 diff --git a/core/src/apps/common/request_pin.py b/core/src/apps/common/request_pin.py index bc38209b5..535013101 100644 --- a/core/src/apps/common/request_pin.py +++ b/core/src/apps/common/request_pin.py @@ -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) diff --git a/core/src/apps/common/seed.py b/core/src/apps/common/seed.py index 81f5003b0..218e00f5f 100644 --- a/core/src/apps/common/seed.py +++ b/core/src/apps/common/seed.py @@ -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 diff --git a/core/src/apps/management/backup_types.py b/core/src/apps/management/backup_types.py index 3a268b66c..cdc58e552 100644 --- a/core/src/apps/management/backup_types.py +++ b/core/src/apps/management/backup_types.py @@ -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 diff --git a/core/src/apps/management/recovery_device/keyboard_bip39.py b/core/src/apps/management/recovery_device/keyboard_bip39.py index e866b6da6..04486f68c 100644 --- a/core/src/apps/management/recovery_device/keyboard_bip39.py +++ b/core/src/apps/management/recovery_device/keyboard_bip39.py @@ -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 diff --git a/core/src/apps/management/recovery_device/keyboard_slip39.py b/core/src/apps/management/recovery_device/keyboard_slip39.py index cafa1e7b4..576064b56 100644 --- a/core/src/apps/management/recovery_device/keyboard_slip39.py +++ b/core/src/apps/management/recovery_device/keyboard_slip39.py @@ -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 diff --git a/core/src/apps/management/recovery_device/layout.py b/core/src/apps/management/recovery_device/layout.py index 38c01af7e..d88211c72 100644 --- a/core/src/apps/management/recovery_device/layout.py +++ b/core/src/apps/management/recovery_device/layout.py @@ -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: diff --git a/core/src/protobuf.py b/core/src/protobuf.py index 3d7cd60c8..9cb0caba5 100644 --- a/core/src/protobuf.py +++ b/core/src/protobuf.py @@ -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] diff --git a/core/src/storage/cache.py b/core/src/storage/cache.py index 9a804f6a3..3234325d1 100644 --- a/core/src/storage/cache.py +++ b/core/src/storage/cache.py @@ -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: diff --git a/core/src/trezor/loop.py b/core/src/trezor/loop.py index aec59ad01..fd6bfdea6 100644 --- a/core/src/trezor/loop.py +++ b/core/src/trezor/loop.py @@ -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) diff --git a/core/src/trezor/ui/components/tt/passphrase.py b/core/src/trezor/ui/components/tt/passphrase.py index d3c6646d8..b9610ae96 100644 --- a/core/src/trezor/ui/components/tt/passphrase.py +++ b/core/src/trezor/ui/components/tt/passphrase.py @@ -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 diff --git a/core/src/trezor/ui/components/tt/swipe.py b/core/src/trezor/ui/components/tt/swipe.py index 90451a123..45d63e6ad 100644 --- a/core/src/trezor/ui/components/tt/swipe.py +++ b/core/src/trezor/ui/components/tt/swipe.py @@ -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) diff --git a/core/src/trezor/utils.py b/core/src/trezor/utils.py index 96bcfd9d5..73e3d24ba 100644 --- a/core/src/trezor/utils.py +++ b/core/src/trezor/utils.py @@ -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 diff --git a/core/src/trezor/wire/__init__.py b/core/src/trezor/wire/__init__.py index 3a513926e..19303cc0d 100644 --- a/core/src/trezor/wire/__init__.py +++ b/core/src/trezor/wire/__init__.py @@ -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( diff --git a/setup.cfg b/setup.cfg index 1d5a93b7b..f0a499431 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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