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

style(python/src): use new syntax for typing

This commit is contained in:
Pavol Rusnak 2020-10-16 19:47:11 +02:00 committed by matejcik
parent 8fd12f4373
commit cd829a99de
9 changed files with 14 additions and 14 deletions

View File

@ -154,7 +154,7 @@ def scalarmult(P: Point, e: int) -> Point:
# Bpow[i] == scalarmult(B, 2**i)
Bpow = [] # type: List[Point]
Bpow: List[Point] = []
def make_Bpow() -> None:

View File

@ -19,7 +19,7 @@ from typing import Optional, Set, Type
from . import protobuf
OMITTED_MESSAGES = set() # type: Set[Type[protobuf.MessageType]]
OMITTED_MESSAGES: Set[Type[protobuf.MessageType]] = set()
DUMP_BYTES = 5
DUMP_PACKETS = 4

View File

@ -584,7 +584,7 @@ def dict_to_proto(message_type: Type[MT], d: Dict[str, Any]) -> MT:
value = [value]
if isinstance(ftype, type) and issubclass(ftype, MessageType):
function = dict_to_proto # type: Callable[[Any, Any], Any]
function: Callable[[Any, Any], Any] = dict_to_proto
else:
function = value_to_proto

View File

@ -63,9 +63,9 @@ def _to_grayscale(data: bytes) -> bytes:
@attr.s
class Toif:
mode = attr.ib() # type: firmware.ToifMode
size = attr.ib() # type: Tuple[int, int]
data = attr.ib() # type: bytes
mode: firmware.ToifMode = attr.ib()
size: Tuple[int, int] = attr.ib()
data: bytes = attr.ib()
@data.validator
def check_data_size(self, _, value):

View File

@ -58,7 +58,7 @@ class Transport:
a Trezor device to a computer.
"""
PATH_PREFIX = None # type: str
PATH_PREFIX: str = None
ENABLED = False
def __str__(self) -> str:
@ -112,7 +112,7 @@ def all_transports() -> Iterable[Type[Transport]]:
def enumerate_devices() -> Iterable[Transport]:
devices = [] # type: List[Transport]
devices: List[Transport] = []
for transport in all_transports():
name = transport.__name__
try:

View File

@ -76,7 +76,7 @@ class BridgeHandleModern(BridgeHandle):
class BridgeHandleLegacy(BridgeHandle):
def __init__(self, transport: "BridgeTransport") -> None:
super().__init__(transport)
self.request = None # type: Optional[str]
self.request: Optional[str] = None
def write_buf(self, buf: bytes) -> None:
if self.request is not None:
@ -110,12 +110,12 @@ class BridgeTransport(Transport):
raise TransportException("Debugging not supported on legacy Bridge")
self.device = device
self.session = None # type: Optional[str]
self.session: Optional[str] = None
self.debug = debug
self.legacy = legacy
if legacy:
self.handle = BridgeHandleLegacy(self) # type: BridgeHandle
self.handle: BridgeHandle = BridgeHandleLegacy(self)
else:
self.handle = BridgeHandleModern(self)

View File

@ -42,7 +42,7 @@ class HidHandle:
) -> None:
self.path = path
self.serial = serial
self.handle = None # type: HidDeviceHandle
self.handle: HidDeviceHandle = None
self.hid_version = None if probe_hid_version else 2
def open(self) -> None:

View File

@ -44,7 +44,7 @@ class UdpTransport(ProtocolBasedTransport):
host = devparts[0]
port = int(devparts[1]) if len(devparts) > 1 else UdpTransport.DEFAULT_PORT
self.device = (host, port)
self.socket = None # type: Optional[socket.socket]
self.socket: Optional[socket.socket] = None
super().__init__(protocol=ProtocolV1(self))

View File

@ -44,7 +44,7 @@ class WebUsbHandle:
self.interface = DEBUG_INTERFACE if debug else INTERFACE
self.endpoint = DEBUG_ENDPOINT if debug else ENDPOINT
self.count = 0
self.handle = None # type: Optional[usb1.USBDeviceHandle]
self.handle: Optional[usb1.USBDeviceHandle] = None
def open(self) -> None:
self.handle = self.device.open()