1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-17 01:52:02 +00:00

flake8: make flake8 better and more strict

this removes some unused variables and also catches a couple bugs
This commit is contained in:
matejcik 2018-04-03 21:25:07 +02:00
parent e3d59eedfb
commit 40ff849228
7 changed files with 44 additions and 53 deletions

View File

@ -1,17 +1,13 @@
[flake8] [flake8]
filename = filename =
*.py, *.py,
trezorctl ./trezorctl
exclude = exclude =
.tox/, .tox/,
build/, build/,
dist/, dist/,
trezorlib/*_pb2.py vendor/,
ignore = ignore =
# F821 undefined name 'unicode'
F821,
# F841 local variable is assigned to but never used
F841,
# F401: module imported but unused # F401: module imported but unused
F401, F401,
# F403: used import * # F403: used import *

View File

@ -29,7 +29,7 @@ install:
script: script:
- python setup.py install - python setup.py install
- flake8 . trezorctl --exclude=vendor - flake8
- tox - tox
notifications: notifications:

View File

@ -111,7 +111,7 @@ class MyTxApiBitcoin(object):
txser = self.serialize_tx(t) txser = self.serialize_tx(t)
txhash = tools.Hash(txser)[::-1] txhash = tools.Hash(txser)[::-1]
outi = self.inputs.append( self.inputs.append(
proto_types.TxInputType( proto_types.TxInputType(
address_n=self.client.expand_path("44'/0'/0'/0/%d" % idx), address_n=self.client.expand_path("44'/0'/0'/0/%d" % idx),
script_type=( script_type=(
@ -178,42 +178,42 @@ def main():
# Get the first address of first BIP44 account # Get the first address of first BIP44 account
# (should be the same address as shown in wallet.trezor.io) # (should be the same address as shown in wallet.trezor.io)
outputs = [ # outputs = [
proto_types.TxOutputType( # proto_types.TxOutputType(
amount=0, # amount=0,
script_type=proto_types.PAYTOADDRESS, # script_type=proto_types.PAYTOADDRESS,
address='p2xtZoXeX5X8BP8JfFhQK2nD3emtjch7UeFm' # address='p2xtZoXeX5X8BP8JfFhQK2nD3emtjch7UeFm'
# op_return_data=binascii.unhexlify('2890770995194662774cd192ee383b805e9a066e6a456be037727649228fb7f6') # # op_return_data=binascii.unhexlify('2890770995194662774cd192ee383b805e9a066e6a456be037727649228fb7f6')
# address_n=client.expand_path("44'/0'/0'/0/35"), # # address_n=client.expand_path("44'/0'/0'/0/35"),
# address='3PUxV6Cc4udQZQsJhArVUzvvVoKC8ohkAj', # # address='3PUxV6Cc4udQZQsJhArVUzvvVoKC8ohkAj',
), # ),
# proto_types.TxOutputType( # proto_types.TxOutputType(
# amount=0, # amount=0,
# script_type=proto_types.PAYTOOPRETURN, # script_type=proto_types.PAYTOOPRETURN,
# op_return_data=binascii.unhexlify('2890770995194662774cd192ee383b805e9a066e6a456be037727649228fb7f6') # op_return_data=binascii.unhexlify('2890770995194662774cd192ee383b805e9a066e6a456be037727649228fb7f6')
# ), # ),
# proto_types.TxOutputType( # proto_types.TxOutputType(
# amount= 8120, # amount= 8120,
# script_type=proto_types.PAYTOADDRESS, # script_type=proto_types.PAYTOADDRESS,
# address_n=client.expand_path("44'/1'/0'/1/0"), # address_n=client.expand_path("44'/1'/0'/1/0"),
# address='1PtCkQgyN6xHmXWzLmFFrDNA5vYhYLeNFZ', # address='1PtCkQgyN6xHmXWzLmFFrDNA5vYhYLeNFZ',
# address='14KRxYgFc7Se8j7MDdrK5PTNv8meq4GivK', # address='14KRxYgFc7Se8j7MDdrK5PTNv8meq4GivK',
# ), # ),
# proto_types.TxOutputType( # proto_types.TxOutputType(
# amount= 18684 - 2000, # amount= 18684 - 2000,
# script_type=proto_types.PAYTOADDRESS, # script_type=proto_types.PAYTOADDRESS,
# address_n=client.expand_path("44'/0'/0'/0/7"), # address_n=client.expand_path("44'/0'/0'/0/7"),
# # address='1PtCkQgyN6xHmXWzLmFFrDNA5vYhYLeNFZ', # # address='1PtCkQgyN6xHmXWzLmFFrDNA5vYhYLeNFZ',
# # address='1s9TSqr3PHZdXGrYws59Uaf5SPqavH43z', # # address='1s9TSqr3PHZdXGrYws59Uaf5SPqavH43z',
# ), # ),
# proto_types.TxOutputType( # proto_types.TxOutputType(
# amount= 1000, # amount= 1000,
# script_type=proto_types.PAYTOADDRESS, # script_type=proto_types.PAYTOADDRESS,
# # address_n=client.expand_path("44'/0'/0'/0/18"), # # address_n=client.expand_path("44'/0'/0'/0/18"),
# # address='1PtCkQgyN6xHmXWzLmFFrDNA5vYhYLeNFZ', # # address='1PtCkQgyN6xHmXWzLmFFrDNA5vYhYLeNFZ',
# # address='1NcMqUvyWv1K3Zxwmx5sqfj7ZEmPCSdJFM', # # address='1NcMqUvyWv1K3Zxwmx5sqfj7ZEmPCSdJFM',
# ), # ),
] # ]
# (signatures, serialized_tx) = client.sign_tx('Testnet', inputs, outputs) # (signatures, serialized_tx) = client.sign_tx('Testnet', inputs, outputs)
(signatures, serialized_tx) = client.sign_tx('Bitcoin', txstore.get_inputs(), txstore.get_outputs()) (signatures, serialized_tx) = client.sign_tx('Bitcoin', txstore.get_inputs(), txstore.get_outputs())

View File

@ -233,7 +233,7 @@ def set_homescreen(connect, filename):
elif filename.endswith('.toif'): elif filename.endswith('.toif'):
img = open(filename, 'rb').read() img = open(filename, 'rb').read()
if img[:8] != b'TOIf\x90\x00\x90\x00': if img[:8] != b'TOIf\x90\x00\x90\x00':
raise CallException(types.Failure_DataError, 'File is not a TOIF file with size of 144x144') raise CallException(proto.FailureType.DataError, 'File is not a TOIF file with size of 144x144')
else: else:
from PIL import Image from PIL import Image
im = Image.open(filename) im = Image.open(filename)

View File

@ -42,11 +42,6 @@ from .protobuf import MessageType
if sys.version_info.major < 3: if sys.version_info.major < 3:
raise Exception("Trezorlib does not support Python 2 anymore.") raise Exception("Trezorlib does not support Python 2 anymore.")
# try:
# from PIL import Image
# SCREENSHOT = True
# except:
# SCREENSHOT = False
SCREENSHOT = False SCREENSHOT = False
@ -424,6 +419,7 @@ class DebugLinkMixin(object):
def call_raw(self, msg): def call_raw(self, msg):
if SCREENSHOT and self.debug: if SCREENSHOT and self.debug:
from PIL import Image
layout = self.debug.read_layout() layout = self.debug.read_layout()
im = Image.new("RGB", (128, 64)) im = Image.new("RGB", (128, 64))
pix = im.load() pix = im.load()
@ -804,7 +800,7 @@ class ProtocolMixin(object):
@session @session
def sign_tx(self, coin_name, inputs, outputs, version=None, lock_time=None, debug_processor=None): def sign_tx(self, coin_name, inputs, outputs, version=None, lock_time=None, debug_processor=None):
start = time.time() # start = time.time()
txes = self._prepare_sign_tx(inputs, outputs) txes = self._prepare_sign_tx(inputs, outputs)
# Prepare and send initial message # Prepare and send initial message

View File

@ -115,4 +115,4 @@ def get_transport(path=None, prefix_search=False):
if transports: if transports:
return transports[0].find_by_path(path, prefix_search=prefix_search) return transports[0].find_by_path(path, prefix_search=prefix_search)
raise Exception("Unknown path prefix '%s'" % prefix) raise Exception("Could not find device by path: {}".format(path))

View File

@ -67,7 +67,6 @@ class UdpTransport(Transport):
@classmethod @classmethod
def enumerate(cls): def enumerate(cls):
devices = []
default_path = '{}:{}'.format(cls.DEFAULT_HOST, cls.DEFAULT_PORT) default_path = '{}:{}'.format(cls.DEFAULT_HOST, cls.DEFAULT_PORT)
try: try:
return [cls._try_path(default_path)] return [cls._try_path(default_path)]