From 16bc1c6cb6fdedb889a55090732d626910cfa672 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Sat, 9 Dec 2017 18:38:36 +0100 Subject: [PATCH] src: fix flake8 style --- .flake8 | 2 ++ src/apps/fido_u2f/__init__.py | 2 +- src/apps/wallet/get_entropy.py | 3 +- src/apps/wallet/sign_tx/helpers.py | 1 - src/apps/wallet/sign_tx/segwit_bip143.py | 1 + src/apps/wallet/sign_tx/signing.py | 8 +++--- .../wallet/sign_tx/tx_weight_calculator.py | 28 +++++++++---------- src/trezor/crypto/bech32.py | 6 ++-- src/trezor/loop.py | 2 +- 9 files changed, 28 insertions(+), 25 deletions(-) diff --git a/.flake8 b/.flake8 index 1acaff2802..f60663aea0 100644 --- a/.flake8 +++ b/.flake8 @@ -11,6 +11,8 @@ ignore = # E501: line too long E501, # F403: star import used, unable to detect undefined names + E741, + # E741 ambiguous variable name F403, # F405: name may be undefined, or defined from star imports F405 diff --git a/src/apps/fido_u2f/__init__.py b/src/apps/fido_u2f/__init__.py index e21b046eee..66b2900c3f 100644 --- a/src/apps/fido_u2f/__init__.py +++ b/src/apps/fido_u2f/__init__.py @@ -415,7 +415,7 @@ class ConfirmContent(ui.Widget): name = knownapps.knownapps[app_id] try: icon = res.load('apps/fido_u2f/res/u2f_%s.toif' % name.lower().replace(' ', '_')) - except: + except FileNotFoundError: icon = res.load('apps/fido_u2f/res/u2f_generic.toif') else: name = '%s...%s' % (ubinascii.hexlify(app_id[:4]), ubinascii.hexlify(app_id[-4:])) diff --git a/src/apps/wallet/get_entropy.py b/src/apps/wallet/get_entropy.py index 396ea21e08..b6510d15b9 100644 --- a/src/apps/wallet/get_entropy.py +++ b/src/apps/wallet/get_entropy.py @@ -23,4 +23,5 @@ async def _show_entropy(ctx): await require_confirm(ctx, Text( 'Confirm entropy', ui.ICON_RESET, ui.BOLD, 'Do you really want', 'to send entropy?', - ui.NORMAL, 'Continue only if you', 'know what you are doing!'),code=ProtectCall) + ui.NORMAL, 'Continue only if you', 'know what you are doing!'), + code=ProtectCall) diff --git a/src/apps/wallet/sign_tx/helpers.py b/src/apps/wallet/sign_tx/helpers.py index f5effa51dd..0d9896c845 100644 --- a/src/apps/wallet/sign_tx/helpers.py +++ b/src/apps/wallet/sign_tx/helpers.py @@ -131,4 +131,3 @@ def sanitize_tx_output(tx: TransactionType) -> TxOutputType: def sanitize_tx_binoutput(tx: TransactionType) -> TxOutputBinType: return tx.bin_outputs[0] - diff --git a/src/apps/wallet/sign_tx/segwit_bip143.py b/src/apps/wallet/sign_tx/segwit_bip143.py index 8168ce1b92..9b9bd35f43 100644 --- a/src/apps/wallet/sign_tx/segwit_bip143.py +++ b/src/apps/wallet/sign_tx/segwit_bip143.py @@ -4,6 +4,7 @@ from trezor.messages import InputScriptType, FailureType from apps.wallet.sign_tx.writers import * + class Bip143Error(ValueError): pass diff --git a/src/apps/wallet/sign_tx/signing.py b/src/apps/wallet/sign_tx/signing.py index 64cfec8be8..4f77e4f706 100644 --- a/src/apps/wallet/sign_tx/signing.py +++ b/src/apps/wallet/sign_tx/signing.py @@ -414,10 +414,10 @@ def output_is_change(o: TxOutputType, wallet_path: list, segwit_in: int) -> bool # segwit inputs paid. this is to prevent user being tricked into # creating ANYONECANSPEND outputs before full segwit activation. return False - return (address_n is not None and wallet_path is not None - and wallet_path == address_n[:-_BIP32_WALLET_DEPTH] - and address_n[-2] == _BIP32_CHANGE_CHAIN - and address_n[-1] <= _BIP32_MAX_LAST_ELEMENT) + return (address_n is not None and wallet_path is not None and + wallet_path == address_n[:-_BIP32_WALLET_DEPTH] and + address_n[-2] == _BIP32_CHANGE_CHAIN and + address_n[-1] <= _BIP32_MAX_LAST_ELEMENT) # Tx Inputs diff --git a/src/apps/wallet/sign_tx/tx_weight_calculator.py b/src/apps/wallet/sign_tx/tx_weight_calculator.py index 77ca663758..88655838f5 100644 --- a/src/apps/wallet/sign_tx/tx_weight_calculator.py +++ b/src/apps/wallet/sign_tx/tx_weight_calculator.py @@ -38,10 +38,10 @@ class TxWeightCalculator: def __init__(self, inputs_count: int, outputs_count: int): self.inputs_count = inputs_count self.counter = 4 * ( - _TXSIZE_HEADER - + _TXSIZE_FOOTER - + self.ser_length_size(inputs_count) - + self.ser_length_size(outputs_count)) + _TXSIZE_HEADER + + _TXSIZE_FOOTER + + self.ser_length_size(inputs_count) + + self.ser_length_size(outputs_count)) self.segwit = False def add_witness_header(self): @@ -54,25 +54,25 @@ class TxWeightCalculator: if i.multisig: multisig_script_size = ( - _TXSIZE_MULTISIGSCRIPT - + i.multisig.pubkeys_count * (1 + _TXSIZE_PUBKEY)) + _TXSIZE_MULTISIGSCRIPT + + i.multisig.pubkeys_count * (1 + _TXSIZE_PUBKEY)) input_script_size = ( - 1 # the OP_FALSE bug in multisig - + i.multisig.m * (1 + _TXSIZE_SIGNATURE) - + self.op_push_size(multisig_script_size) - + multisig_script_size) + 1 + # the OP_FALSE bug in multisig + i.multisig.m * (1 + _TXSIZE_SIGNATURE) + + self.op_push_size(multisig_script_size) + + multisig_script_size) else: input_script_size = 1 + _TXSIZE_SIGNATURE + 1 + _TXSIZE_PUBKEY self.counter += 4 * _TXSIZE_INPUT - if (i.script_type == InputScriptType.SPENDADDRESS - or i.script_type == InputScriptType.SPENDMULTISIG): + if (i.script_type == InputScriptType.SPENDADDRESS or + i.script_type == InputScriptType.SPENDMULTISIG): input_script_size += self.ser_length_size(input_script_size) self.counter += 4 * input_script_size - elif (i.script_type == InputScriptType.SPENDWITNESS - or i.script_type == InputScriptType.SPENDP2SHWITNESS): + elif (i.script_type == InputScriptType.SPENDWITNESS or + i.script_type == InputScriptType.SPENDP2SHWITNESS): self.add_witness_header() if i.script_type == InputScriptType.SPENDP2SHWITNESS: if i.multisig: diff --git a/src/trezor/crypto/bech32.py b/src/trezor/crypto/bech32.py index e0df3b6a67..68f2468748 100644 --- a/src/trezor/crypto/bech32.py +++ b/src/trezor/crypto/bech32.py @@ -68,10 +68,10 @@ def bech32_decode(bech): pos = bech.rfind('1') if pos < 1 or pos + 7 > len(bech) or len(bech) > 90: return (None, None) - if not all(x in CHARSET for x in bech[pos+1:]): + if not all(x in CHARSET for x in bech[pos + 1:]): return (None, None) hrp = bech[:pos] - data = [CHARSET.find(x) for x in bech[pos+1:]] + data = [CHARSET.find(x) for x in bech[pos + 1:]] if not bech32_verify_checksum(hrp, data): return (None, None) return (hrp, data[:-6]) @@ -120,4 +120,4 @@ def encode(hrp, witver, witprog): ret = bech32_encode(hrp, [witver] + convertbits(witprog, 8, 5)) if decode(hrp, ret) == (None, None): return None - return ret \ No newline at end of file + return ret diff --git a/src/trezor/loop.py b/src/trezor/loop.py index 83e3393647..bfaffa0fde 100644 --- a/src/trezor/loop.py +++ b/src/trezor/loop.py @@ -285,7 +285,7 @@ class wait(Syscall): def __iter__(self): try: return (yield self) - except: + except Exception: # exception was raised on the waiting task externally with # close() or throw(), kill the children tasks and re-raise self.exit()