mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 04:18:10 +00:00
style(python/src): use new syntax for typing
This commit is contained in:
parent
8fd12f4373
commit
cd829a99de
@ -154,7 +154,7 @@ def scalarmult(P: Point, e: int) -> Point:
|
|||||||
|
|
||||||
|
|
||||||
# Bpow[i] == scalarmult(B, 2**i)
|
# Bpow[i] == scalarmult(B, 2**i)
|
||||||
Bpow = [] # type: List[Point]
|
Bpow: List[Point] = []
|
||||||
|
|
||||||
|
|
||||||
def make_Bpow() -> None:
|
def make_Bpow() -> None:
|
||||||
|
@ -19,7 +19,7 @@ from typing import Optional, Set, Type
|
|||||||
|
|
||||||
from . import protobuf
|
from . import protobuf
|
||||||
|
|
||||||
OMITTED_MESSAGES = set() # type: Set[Type[protobuf.MessageType]]
|
OMITTED_MESSAGES: Set[Type[protobuf.MessageType]] = set()
|
||||||
|
|
||||||
DUMP_BYTES = 5
|
DUMP_BYTES = 5
|
||||||
DUMP_PACKETS = 4
|
DUMP_PACKETS = 4
|
||||||
|
@ -584,7 +584,7 @@ def dict_to_proto(message_type: Type[MT], d: Dict[str, Any]) -> MT:
|
|||||||
value = [value]
|
value = [value]
|
||||||
|
|
||||||
if isinstance(ftype, type) and issubclass(ftype, MessageType):
|
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:
|
else:
|
||||||
function = value_to_proto
|
function = value_to_proto
|
||||||
|
|
||||||
|
@ -63,9 +63,9 @@ def _to_grayscale(data: bytes) -> bytes:
|
|||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
class Toif:
|
class Toif:
|
||||||
mode = attr.ib() # type: firmware.ToifMode
|
mode: firmware.ToifMode = attr.ib()
|
||||||
size = attr.ib() # type: Tuple[int, int]
|
size: Tuple[int, int] = attr.ib()
|
||||||
data = attr.ib() # type: bytes
|
data: bytes = attr.ib()
|
||||||
|
|
||||||
@data.validator
|
@data.validator
|
||||||
def check_data_size(self, _, value):
|
def check_data_size(self, _, value):
|
||||||
|
@ -58,7 +58,7 @@ class Transport:
|
|||||||
a Trezor device to a computer.
|
a Trezor device to a computer.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
PATH_PREFIX = None # type: str
|
PATH_PREFIX: str = None
|
||||||
ENABLED = False
|
ENABLED = False
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
@ -112,7 +112,7 @@ def all_transports() -> Iterable[Type[Transport]]:
|
|||||||
|
|
||||||
|
|
||||||
def enumerate_devices() -> Iterable[Transport]:
|
def enumerate_devices() -> Iterable[Transport]:
|
||||||
devices = [] # type: List[Transport]
|
devices: List[Transport] = []
|
||||||
for transport in all_transports():
|
for transport in all_transports():
|
||||||
name = transport.__name__
|
name = transport.__name__
|
||||||
try:
|
try:
|
||||||
|
@ -76,7 +76,7 @@ class BridgeHandleModern(BridgeHandle):
|
|||||||
class BridgeHandleLegacy(BridgeHandle):
|
class BridgeHandleLegacy(BridgeHandle):
|
||||||
def __init__(self, transport: "BridgeTransport") -> None:
|
def __init__(self, transport: "BridgeTransport") -> None:
|
||||||
super().__init__(transport)
|
super().__init__(transport)
|
||||||
self.request = None # type: Optional[str]
|
self.request: Optional[str] = None
|
||||||
|
|
||||||
def write_buf(self, buf: bytes) -> None:
|
def write_buf(self, buf: bytes) -> None:
|
||||||
if self.request is not None:
|
if self.request is not None:
|
||||||
@ -110,12 +110,12 @@ class BridgeTransport(Transport):
|
|||||||
raise TransportException("Debugging not supported on legacy Bridge")
|
raise TransportException("Debugging not supported on legacy Bridge")
|
||||||
|
|
||||||
self.device = device
|
self.device = device
|
||||||
self.session = None # type: Optional[str]
|
self.session: Optional[str] = None
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.legacy = legacy
|
self.legacy = legacy
|
||||||
|
|
||||||
if legacy:
|
if legacy:
|
||||||
self.handle = BridgeHandleLegacy(self) # type: BridgeHandle
|
self.handle: BridgeHandle = BridgeHandleLegacy(self)
|
||||||
else:
|
else:
|
||||||
self.handle = BridgeHandleModern(self)
|
self.handle = BridgeHandleModern(self)
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class HidHandle:
|
|||||||
) -> None:
|
) -> None:
|
||||||
self.path = path
|
self.path = path
|
||||||
self.serial = serial
|
self.serial = serial
|
||||||
self.handle = None # type: HidDeviceHandle
|
self.handle: HidDeviceHandle = None
|
||||||
self.hid_version = None if probe_hid_version else 2
|
self.hid_version = None if probe_hid_version else 2
|
||||||
|
|
||||||
def open(self) -> None:
|
def open(self) -> None:
|
||||||
|
@ -44,7 +44,7 @@ class UdpTransport(ProtocolBasedTransport):
|
|||||||
host = devparts[0]
|
host = devparts[0]
|
||||||
port = int(devparts[1]) if len(devparts) > 1 else UdpTransport.DEFAULT_PORT
|
port = int(devparts[1]) if len(devparts) > 1 else UdpTransport.DEFAULT_PORT
|
||||||
self.device = (host, port)
|
self.device = (host, port)
|
||||||
self.socket = None # type: Optional[socket.socket]
|
self.socket: Optional[socket.socket] = None
|
||||||
|
|
||||||
super().__init__(protocol=ProtocolV1(self))
|
super().__init__(protocol=ProtocolV1(self))
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class WebUsbHandle:
|
|||||||
self.interface = DEBUG_INTERFACE if debug else INTERFACE
|
self.interface = DEBUG_INTERFACE if debug else INTERFACE
|
||||||
self.endpoint = DEBUG_ENDPOINT if debug else ENDPOINT
|
self.endpoint = DEBUG_ENDPOINT if debug else ENDPOINT
|
||||||
self.count = 0
|
self.count = 0
|
||||||
self.handle = None # type: Optional[usb1.USBDeviceHandle]
|
self.handle: Optional[usb1.USBDeviceHandle] = None
|
||||||
|
|
||||||
def open(self) -> None:
|
def open(self) -> None:
|
||||||
self.handle = self.device.open()
|
self.handle = self.device.open()
|
||||||
|
Loading…
Reference in New Issue
Block a user