diff --git a/python/Makefile b/python/Makefile index c422b75b7..c13fad930 100644 --- a/python/Makefile +++ b/python/Makefile @@ -3,7 +3,6 @@ SETUP=$(PYTHON) setup.py EXCLUDES=.vscode STYLE_TARGETS=src/trezorlib setup.py -EXCLUDE_TARGETS=messages all: build @@ -46,20 +45,20 @@ git-clean: style: black $(STYLE_TARGETS) - isort --apply --recursive $(STYLE_TARGETS) --skip-glob "$(EXCLUDE_TARGETS)/*" - autoflake -i --remove-all-unused-imports -r $(STYLE_TARGETS) --exclude "$(EXCLUDE_TARGETS)" + isort --apply --recursive $(STYLE_TARGETS) + autoflake -i --remove-all-unused-imports -r $(STYLE_TARGETS) flake8 make pyright style_check: black --check $(STYLE_TARGETS) - isort --check-only --recursive $(STYLE_TARGETS) --skip-glob "$(EXCLUDE_TARGETS)/*" + isort --check-only $(STYLE_TARGETS) flake8 make pyright style_quick_check: black --check $(STYLE_TARGETS) - isort --check-only --recursive $(STYLE_TARGETS) --skip-glob "$(EXCLUDE_TARGETS)/*" + isort --check-only $(STYLE_TARGETS) .PHONY: all build install clean style style_check git-clean clean-build clean-pyc clean-test diff --git a/python/setup.cfg b/python/setup.cfg index 76e8589ba..e801ad666 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -28,15 +28,7 @@ per-file-ignores = known-modules = libusb1:[usb1],hidapi:[hid],PyQt5:[PyQt5.QtWidgets,PyQt5.QtGui,PyQt5.QtCore],simple-rlp:[rlp] [isort] -multi_line_output = 3 -include_trailing_comma = True -force_grid_wrap = 0 -combine_as_imports = True -line_length = 88 -not_skip=__init__.py -known_first_party=trezorlib -known_third_party=hidapi, rlp, ethjsonrpc, ecdsa, mnemonic, shamir_mnemonic, requests, click, pyblake2, \ - usb, construct, pytest +profile = black [mypy] check_untyped_defs = True diff --git a/python/src/trezorlib/binance.py b/python/src/trezorlib/binance.py index d8ac31480..0334f2e2e 100644 --- a/python/src/trezorlib/binance.py +++ b/python/src/trezorlib/binance.py @@ -22,8 +22,8 @@ from .tools import expect, session if TYPE_CHECKING: from .client import TrezorClient - from .tools import Address from .protobuf import MessageType + from .tools import Address @expect(messages.BinanceAddress, field="address", ret_type=str) diff --git a/python/src/trezorlib/btc.py b/python/src/trezorlib/btc.py index 1e88b71a8..af0b722a0 100644 --- a/python/src/trezorlib/btc.py +++ b/python/src/trezorlib/btc.py @@ -27,8 +27,8 @@ from .tools import expect, prepare_message_bytes, session if TYPE_CHECKING: from .client import TrezorClient - from .tools import Address from .protobuf import MessageType + from .tools import Address class ScriptSig(TypedDict): asm: str diff --git a/python/src/trezorlib/cli/__init__.py b/python/src/trezorlib/cli/__init__.py index 41b03c6fe..8a4191a8e 100644 --- a/python/src/trezorlib/cli/__init__.py +++ b/python/src/trezorlib/cli/__init__.py @@ -26,13 +26,14 @@ from ..client import TrezorClient from ..ui import ClickUI, ScriptUI if TYPE_CHECKING: - from ..transport import Transport - from ..ui import TrezorClientUI - # Needed to enforce a return value from decorators # More details: https://www.python.org/dev/peps/pep-0612/ from typing import TypeVar - from typing_extensions import ParamSpec, Concatenate + + from typing_extensions import Concatenate, ParamSpec + + from ..transport import Transport + from ..ui import TrezorClientUI P = ParamSpec("P") R = TypeVar("R") diff --git a/python/src/trezorlib/cli/cosi.py b/python/src/trezorlib/cli/cosi.py index e11e64dc6..eaa7b95a3 100644 --- a/python/src/trezorlib/cli/cosi.py +++ b/python/src/trezorlib/cli/cosi.py @@ -22,8 +22,8 @@ from .. import cosi, tools from . import with_client if TYPE_CHECKING: - from ..client import TrezorClient from .. import messages + from ..client import TrezorClient PATH_HELP = "BIP-32 path, e.g. m/10018'/0'" diff --git a/python/src/trezorlib/cli/device.py b/python/src/trezorlib/cli/device.py index c8f6e6104..f2dcb1ef5 100644 --- a/python/src/trezorlib/cli/device.py +++ b/python/src/trezorlib/cli/device.py @@ -24,8 +24,8 @@ from . import ChoiceType, with_client if TYPE_CHECKING: from ..client import TrezorClient - from . import TrezorConnection from ..protobuf import MessageType + from . import TrezorConnection RECOVERY_TYPE = { "scrambled": messages.RecoveryDeviceType.ScrambledWords, diff --git a/python/src/trezorlib/cli/eos.py b/python/src/trezorlib/cli/eos.py index 7f7cf676f..93800294a 100644 --- a/python/src/trezorlib/cli/eos.py +++ b/python/src/trezorlib/cli/eos.py @@ -23,8 +23,8 @@ from .. import eos, tools from . import with_client if TYPE_CHECKING: - from ..client import TrezorClient from .. import messages + from ..client import TrezorClient PATH_HELP = "BIP-32 path, e.g. m/44'/194'/0'/0/0" diff --git a/python/src/trezorlib/cli/ethereum.py b/python/src/trezorlib/cli/ethereum.py index 8a0e1ba2e..4abe3adb4 100644 --- a/python/src/trezorlib/cli/ethereum.py +++ b/python/src/trezorlib/cli/ethereum.py @@ -40,6 +40,7 @@ from . import with_client if TYPE_CHECKING: import web3 + from ..client import TrezorClient PATH_HELP = "BIP-32 path, e.g. m/44'/60'/0'/0/0" diff --git a/python/src/trezorlib/cli/stellar.py b/python/src/trezorlib/cli/stellar.py index d9c9fb6a4..f10454aed 100644 --- a/python/src/trezorlib/cli/stellar.py +++ b/python/src/trezorlib/cli/stellar.py @@ -28,8 +28,8 @@ if TYPE_CHECKING: try: from stellar_sdk import ( - parse_transaction_envelope_from_xdr, FeeBumpTransactionEnvelope, + parse_transaction_envelope_from_xdr, ) except ImportError: pass diff --git a/python/src/trezorlib/client.py b/python/src/trezorlib/client.py index dd0e47711..4ad5a155d 100644 --- a/python/src/trezorlib/client.py +++ b/python/src/trezorlib/client.py @@ -28,8 +28,8 @@ from .tools import expect, parse_path, session if TYPE_CHECKING: from .protobuf import MessageType - from .ui import TrezorClientUI from .transport import Transport + from .ui import TrezorClientUI UI = TypeVar("UI", bound="TrezorClientUI") diff --git a/python/src/trezorlib/cosi.py b/python/src/trezorlib/cosi.py index f8e423790..0501abdec 100644 --- a/python/src/trezorlib/cosi.py +++ b/python/src/trezorlib/cosi.py @@ -23,8 +23,8 @@ from .tools import expect if TYPE_CHECKING: from .client import TrezorClient - from .tools import Address from .protobuf import MessageType + from .tools import Address # XXX, these could be NewType's, but that would infect users of the cosi module with these types as well. # Unsure if we want that. diff --git a/python/src/trezorlib/debuglink.py b/python/src/trezorlib/debuglink.py index 29b4213ed..1bfe72894 100644 --- a/python/src/trezorlib/debuglink.py +++ b/python/src/trezorlib/debuglink.py @@ -51,8 +51,8 @@ from .log import DUMP_BYTES from .tools import expect if TYPE_CHECKING: - from .transport import Transport from .messages import PinMatrixRequestType + from .transport import Transport ExpectedMessage = Union[ protobuf.MessageType, Type[protobuf.MessageType], "MessageFilter" diff --git a/python/src/trezorlib/eos.py b/python/src/trezorlib/eos.py index 7be0e5674..a56059087 100644 --- a/python/src/trezorlib/eos.py +++ b/python/src/trezorlib/eos.py @@ -22,8 +22,8 @@ from .tools import b58decode, expect, session if TYPE_CHECKING: from .client import TrezorClient - from .tools import Address from .protobuf import MessageType + from .tools import Address def name_to_number(name: str) -> int: diff --git a/python/src/trezorlib/ethereum.py b/python/src/trezorlib/ethereum.py index 92c1c2395..adf4408ad 100644 --- a/python/src/trezorlib/ethereum.py +++ b/python/src/trezorlib/ethereum.py @@ -22,8 +22,8 @@ from .tools import expect, prepare_message_bytes, session, unharden if TYPE_CHECKING: from .client import TrezorClient - from .tools import Address from .protobuf import MessageType + from .tools import Address def int_to_big_endian(value: int) -> bytes: diff --git a/python/src/trezorlib/misc.py b/python/src/trezorlib/misc.py index cd4d2b4c9..4ed6f5aa8 100644 --- a/python/src/trezorlib/misc.py +++ b/python/src/trezorlib/misc.py @@ -20,9 +20,9 @@ from . import messages from .tools import expect if TYPE_CHECKING: - from .tools import Address from .client import TrezorClient from .protobuf import MessageType + from .tools import Address @expect(messages.Entropy, field="entropy", ret_type=bytes) diff --git a/python/src/trezorlib/monero.py b/python/src/trezorlib/monero.py index 4b9187f16..dbb65aa20 100644 --- a/python/src/trezorlib/monero.py +++ b/python/src/trezorlib/monero.py @@ -21,8 +21,8 @@ from .tools import expect if TYPE_CHECKING: from .client import TrezorClient - from .tools import Address from .protobuf import MessageType + from .tools import Address # MAINNET = 0 diff --git a/python/src/trezorlib/nem.py b/python/src/trezorlib/nem.py index 4d3e06261..9b948992d 100644 --- a/python/src/trezorlib/nem.py +++ b/python/src/trezorlib/nem.py @@ -22,8 +22,8 @@ from .tools import expect if TYPE_CHECKING: from .client import TrezorClient - from .tools import Address from .protobuf import MessageType + from .tools import Address TYPE_TRANSACTION_TRANSFER = 0x0101 TYPE_IMPORTANCE_TRANSFER = 0x0801 diff --git a/python/src/trezorlib/qt/pinmatrix.py b/python/src/trezorlib/qt/pinmatrix.py index 389e376d6..09c757e2d 100644 --- a/python/src/trezorlib/qt/pinmatrix.py +++ b/python/src/trezorlib/qt/pinmatrix.py @@ -19,33 +19,33 @@ import sys from typing import Any try: + from PyQt5.QtCore import QT_VERSION_STR, QRegExp, Qt + from PyQt5.QtGui import QRegExpValidator from PyQt5.QtWidgets import ( - QPushButton, - QLineEdit, - QSizePolicy, - QLabel, QApplication, - QWidget, QGridLayout, - QVBoxLayout, QHBoxLayout, + QLabel, + QLineEdit, + QPushButton, + QSizePolicy, + QVBoxLayout, + QWidget, ) - from PyQt5.QtGui import QRegExpValidator - from PyQt5.QtCore import QRegExp, Qt, QT_VERSION_STR except Exception: + from PyQt4.QtCore import QT_VERSION_STR, SIGNAL, QObject, QRegExp, Qt # noqa: I from PyQt4.QtGui import ( # noqa: I - QPushButton, - QLineEdit, - QSizePolicy, - QRegExpValidator, - QLabel, QApplication, - QWidget, QGridLayout, - QVBoxLayout, QHBoxLayout, + QLabel, + QLineEdit, + QPushButton, + QRegExpValidator, + QSizePolicy, + QVBoxLayout, + QWidget, ) - from PyQt4.QtCore import QObject, SIGNAL, QRegExp, Qt, QT_VERSION_STR # noqa: I class PinButton(QPushButton): diff --git a/python/src/trezorlib/ripple.py b/python/src/trezorlib/ripple.py index ad421b2ca..534d4c502 100644 --- a/python/src/trezorlib/ripple.py +++ b/python/src/trezorlib/ripple.py @@ -22,8 +22,8 @@ from .tools import dict_from_camelcase, expect if TYPE_CHECKING: from .client import TrezorClient - from .tools import Address from .protobuf import MessageType + from .tools import Address REQUIRED_FIELDS = ("Fee", "Sequence", "TransactionType", "Payment") REQUIRED_PAYMENT_FIELDS = ("Amount", "Destination") diff --git a/python/src/trezorlib/stellar.py b/python/src/trezorlib/stellar.py index 1cb0c99b8..0670ac755 100644 --- a/python/src/trezorlib/stellar.py +++ b/python/src/trezorlib/stellar.py @@ -21,8 +21,8 @@ from . import exceptions, messages from .tools import expect if TYPE_CHECKING: - from .protobuf import MessageType from .client import TrezorClient + from .protobuf import MessageType from .tools import Address StellarMessageType = Union[ @@ -52,22 +52,22 @@ try: CreatePassiveSellOffer, HashMemo, IdMemo, + ManageBuyOffer, ManageData, ManageSellOffer, + MuxedAccount, + Network, NoneMemo, Operation, PathPaymentStrictReceive, PathPaymentStrictSend, Payment, + Price, ReturnHashMemo, SetOptions, TextMemo, TransactionEnvelope, TrustLineEntryFlag, - Price, - Network, - ManageBuyOffer, - MuxedAccount, ) from stellar_sdk.xdr.signer_key_type import SignerKeyType diff --git a/python/src/trezorlib/tezos.py b/python/src/trezorlib/tezos.py index 7e7e63f2c..89b1b4fef 100644 --- a/python/src/trezorlib/tezos.py +++ b/python/src/trezorlib/tezos.py @@ -21,8 +21,8 @@ from .tools import expect if TYPE_CHECKING: from .client import TrezorClient - from .tools import Address from .protobuf import MessageType + from .tools import Address @expect(messages.TezosAddress, field="address", ret_type=str) diff --git a/python/src/trezorlib/tools.py b/python/src/trezorlib/tools.py index 9e3d90143..e5c32b4de 100644 --- a/python/src/trezorlib/tools.py +++ b/python/src/trezorlib/tools.py @@ -36,13 +36,14 @@ from typing import ( import construct if TYPE_CHECKING: - from .client import TrezorClient - from .protobuf import MessageType - # Needed to enforce a return value from decorators # More details: https://www.python.org/dev/peps/pep-0612/ from typing import TypeVar - from typing_extensions import ParamSpec, Concatenate + + from typing_extensions import Concatenate, ParamSpec + + from .client import TrezorClient + from .protobuf import MessageType MT = TypeVar("MT", bound=MessageType) P = ParamSpec("P")