From cb7bc8f410c6eb6a20a1171b2ecaf28e4ae69c49 Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Thu, 8 Aug 2019 16:03:50 +0200 Subject: [PATCH] core: Fix mypy warnings. --- core/src/apps/common/cbor.py | 6 +++--- core/src/apps/webauthn/knownapps.py | 2 +- core/src/trezor/ui/__init__.py | 6 ++---- core/src/trezor/ui/confirm.py | 11 +++++++---- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/core/src/apps/common/cbor.py b/core/src/apps/common/cbor.py index 95789091d..deab4ac14 100644 --- a/core/src/apps/common/cbor.py +++ b/core/src/apps/common/cbor.py @@ -8,7 +8,7 @@ from micropython import const from trezor import log if False: - from typing import Any, Dict, Iterable, List, Tuple + from typing import Any, Iterable, List, Tuple Value = Any @@ -146,7 +146,7 @@ def _cbor_decode(cbor: bytes) -> Tuple[Value, bytes]: return (bytes(data[0:ln]).decode(), data[ln:]) elif fb_type == _CBOR_ARRAY: if fb_aux == _CBOR_VAR_FOLLOWS: - res = [] + res = [] # type: Value data = cbor[1:] while True: item, data = _cbor_decode(data) @@ -162,7 +162,7 @@ def _cbor_decode(cbor: bytes) -> Tuple[Value, bytes]: res.append(item) return (res, data) elif fb_type == _CBOR_MAP: - res = {} # type: Dict[Value, Value] + res = {} if fb_aux == _CBOR_VAR_FOLLOWS: data = cbor[1:] while True: diff --git a/core/src/apps/webauthn/knownapps.py b/core/src/apps/webauthn/knownapps.py index f2e8b59bc..faccbfd0b 100644 --- a/core/src/apps/webauthn/knownapps.py +++ b/core/src/apps/webauthn/knownapps.py @@ -34,4 +34,4 @@ _knownapps = { "demo.yubico.com": "demo.yubico.com", } -knownapps = {sha256(k).digest(): v for (k, v) in _knownapps.items()} +knownapps = {sha256(k.encode()).digest(): v for (k, v) in _knownapps.items()} diff --git a/core/src/trezor/ui/__init__.py b/core/src/trezor/ui/__init__.py index d89c8ad73..d27ecfe06 100644 --- a/core/src/trezor/ui/__init__.py +++ b/core/src/trezor/ui/__init__.py @@ -10,6 +10,8 @@ if False: Pos = Tuple[int, int] Area = Tuple[int, int, int, int] + ResultValue = TypeVar("ResultValue") + display = Display() @@ -186,10 +188,6 @@ class LayoutCancelled(Exception): pass -if False: - ResultValue = TypeVar("ResultValue") - - class Result(Exception): def __init__(self, value: ResultValue) -> None: self.value = value diff --git a/core/src/trezor/ui/confirm.py b/core/src/trezor/ui/confirm.py index f5d611f58..772c0183d 100644 --- a/core/src/trezor/ui/confirm.py +++ b/core/src/trezor/ui/confirm.py @@ -3,6 +3,7 @@ from trezor.ui.button import Button, ButtonCancel, ButtonConfirm from trezor.ui.loader import Loader, LoaderDefault if False: + from typing import Optional from trezor.ui.button import ButtonContent, ButtonStyleType from trezor.ui.loader import LoaderStyleType @@ -19,9 +20,9 @@ class Confirm(ui.Layout): def __init__( self, content: ui.Control, - confirm: ButtonContent = DEFAULT_CONFIRM, + confirm: Optional[ButtonContent] = DEFAULT_CONFIRM, confirm_style: ButtonStyleType = DEFAULT_CONFIRM_STYLE, - cancel: ButtonContent = DEFAULT_CANCEL, + cancel: Optional[ButtonContent] = DEFAULT_CANCEL, cancel_style: ButtonStyleType = DEFAULT_CANCEL_STYLE, major_confirm: bool = False, ) -> None: @@ -34,7 +35,9 @@ class Confirm(ui.Layout): area = ui.grid(13, cells_x=2) else: area = ui.grid(9, n_x=2) - self.confirm = Button(area, confirm, confirm_style) + self.confirm = Button( + area, confirm, confirm_style + ) # type: Optional[Button] self.confirm.on_click = self.on_confirm # type: ignore else: self.confirm = None @@ -46,7 +49,7 @@ class Confirm(ui.Layout): area = ui.grid(12, cells_x=1) else: area = ui.grid(8, n_x=2) - self.cancel = Button(area, cancel, cancel_style) + self.cancel = Button(area, cancel, cancel_style) # type: Optional[Button] self.cancel.on_click = self.on_cancel # type: ignore else: self.cancel = None