mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-29 16:51:30 +00:00
fix(python): improve type checking
This commit is contained in:
parent
00304471ca
commit
c4bf4fa884
1
python/.changelog.d/2832.fixed
Normal file
1
python/.changelog.d/2832.fixed
Normal file
@ -0,0 +1 @@
|
|||||||
|
Improve typing information when `TrezorClient` has a more intelligent UI object.
|
@ -17,7 +17,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import warnings
|
import warnings
|
||||||
from typing import TYPE_CHECKING, Any, Optional
|
from typing import TYPE_CHECKING, Any, Generic, Optional, TypeVar
|
||||||
|
|
||||||
from mnemonic import Mnemonic
|
from mnemonic import Mnemonic
|
||||||
|
|
||||||
@ -31,6 +31,8 @@ if TYPE_CHECKING:
|
|||||||
from .ui import TrezorClientUI
|
from .ui import TrezorClientUI
|
||||||
from .transport import Transport
|
from .transport import Transport
|
||||||
|
|
||||||
|
UI = TypeVar("UI", bound="TrezorClientUI")
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
MAX_PASSPHRASE_LENGTH = 50
|
MAX_PASSPHRASE_LENGTH = 50
|
||||||
@ -70,7 +72,7 @@ def get_default_client(
|
|||||||
return TrezorClient(transport, ui, **kwargs)
|
return TrezorClient(transport, ui, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class TrezorClient:
|
class TrezorClient(Generic[UI]):
|
||||||
"""Trezor client, a connection to a Trezor device.
|
"""Trezor client, a connection to a Trezor device.
|
||||||
|
|
||||||
This class allows you to manage connection state, send and receive protobuf
|
This class allows you to manage connection state, send and receive protobuf
|
||||||
@ -81,7 +83,7 @@ class TrezorClient:
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
transport: "Transport",
|
transport: "Transport",
|
||||||
ui: "TrezorClientUI",
|
ui: UI,
|
||||||
session_id: Optional[bytes] = None,
|
session_id: Optional[bytes] = None,
|
||||||
derive_cardano: Optional[bool] = None,
|
derive_cardano: Optional[bool] = None,
|
||||||
model: Optional[models.TrezorModel] = None,
|
model: Optional[models.TrezorModel] = None,
|
||||||
|
@ -109,7 +109,7 @@ class BridgeTransport(Transport):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
PATH_PREFIX = "bridge"
|
PATH_PREFIX = "bridge"
|
||||||
ENABLED = True
|
ENABLED: bool = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, device: Dict[str, Any], legacy: bool, debug: bool = False
|
self, device: Dict[str, Any], legacy: bool, debug: bool = False
|
||||||
|
@ -36,7 +36,7 @@ class UdpTransport(ProtocolBasedTransport):
|
|||||||
DEFAULT_HOST = "127.0.0.1"
|
DEFAULT_HOST = "127.0.0.1"
|
||||||
DEFAULT_PORT = 21324
|
DEFAULT_PORT = 21324
|
||||||
PATH_PREFIX = "udp"
|
PATH_PREFIX = "udp"
|
||||||
ENABLED = True
|
ENABLED: bool = True
|
||||||
|
|
||||||
def __init__(self, device: Optional[str] = None) -> None:
|
def __init__(self, device: Optional[str] = None) -> None:
|
||||||
if not device:
|
if not device:
|
||||||
|
Loading…
Reference in New Issue
Block a user