diff --git a/.cirrus.yml b/.cirrus.yml index 1a2d278d7..7388443e3 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -151,7 +151,7 @@ task: folder: ~/.cache/pip fingerprint_script: echo Flake8 && echo $ELECTRUM_IMAGE && cat $ELECTRUM_REQUIREMENTS install_script: - - pip install "flake8==7.2.0" "flake8-bugbear==24.12.12" # flake8-commas + - pip install "flake8==7.2.0" "flake8-bugbear==24.12.12" flake8_script: - flake8 . --count --select="$ELECTRUM_LINTERS" --ignore="$ELECTRUM_LINTERS_IGNORE" --show-source --statistics --exclude "*_pb2.py,electrum/_vendor/" env: @@ -164,8 +164,8 @@ task: # - https://flake8.pycqa.org/en/latest/user/error-codes.html # - https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes # - https://github.com/PyCQA/flake8-bugbear/tree/8c0e7eb04217494d48d0ab093bf5b31db0921989#list-of-warnings - ELECTRUM_LINTERS: E9,E101,E129,E273,E274,E703,E71,E722,F63,F7,F82,W191,W29,B - ELECTRUM_LINTERS_IGNORE: B007,B009,B010,B019,B036 + ELECTRUM_LINTERS: E9,E101,E129,E273,E274,E703,E71,E722,F5,F6,F7,F8,W191,W29,B + ELECTRUM_LINTERS_IGNORE: B007,B009,B010,B019,B036,F541,F841 - name: "linter: Flake8 Non-Mandatory" env: ELECTRUM_LINTERS: E,F,W,C90,B diff --git a/electrum/commands.py b/electrum/commands.py index c2015d2dc..1e7f0c983 100644 --- a/electrum/commands.py +++ b/electrum/commands.py @@ -45,7 +45,7 @@ from . import util from .lnmsg import OnionWireSerializer from .logging import Logger from .onion_message import create_blinded_path, send_onion_message_to -from .util import (bfh, format_satoshis, json_decode, json_normalize, is_hash256_str, is_hex_str, to_bytes, +from .util import (bfh, json_decode, json_normalize, is_hash256_str, is_hex_str, to_bytes, parse_max_spend, to_decimal, UserFacingException, InvalidPassword) from . import bitcoin @@ -434,7 +434,6 @@ class Commands(Logger): arg:str:seed_type:The type of seed to create, e.g. 'standard' or 'segwit' arg:str:language:Default language for wordlist """ - from .mnemonic import Mnemonic s = Mnemonic(language).make_seed(seed_type=seed_type, num_bits=nbits) return s @@ -1156,7 +1155,7 @@ class Commands(Logger): if labels or balance: item = (item,) if balance: - item += (format_satoshis(sum(wallet.get_addr_balance(addr))),) + item += (util.format_satoshis(sum(wallet.get_addr_balance(addr))),) if labels: item += (repr(wallet.get_label_for_address(addr)),) out.append(item) diff --git a/electrum/gui/qt/wizard/wallet.py b/electrum/gui/qt/wizard/wallet.py index d64fd471f..fa592b143 100644 --- a/electrum/gui/qt/wizard/wallet.py +++ b/electrum/gui/qt/wizard/wallet.py @@ -34,7 +34,6 @@ from electrum.gui.qt.util import (PasswordLineEdit, char_width_in_lineedit, WWLa if TYPE_CHECKING: from electrum.simple_config import SimpleConfig from electrum.plugin import Plugins - from electrum.daemon import Daemon from electrum.gui.qt import QElectrumApplication WIF_HELP_TEXT = (_('WIF keys are typed in Electrum, based on script type.') + '\n\n' + diff --git a/electrum/lntransport.py b/electrum/lntransport.py index 59d9ac6be..716f35e65 100644 --- a/electrum/lntransport.py +++ b/electrum/lntransport.py @@ -9,7 +9,6 @@ import re import hashlib import asyncio from asyncio import StreamReader, StreamWriter -from typing import Optional, TYPE_CHECKING from functools import cached_property from typing import NamedTuple, List, Tuple, Mapping, Optional, TYPE_CHECKING, Union, Dict, Set, Sequence diff --git a/electrum/plugin.py b/electrum/plugin.py index c4d9996e6..8ee89cb1e 100644 --- a/electrum/plugin.py +++ b/electrum/plugin.py @@ -963,7 +963,7 @@ class DeviceMgr(ThreadJob): @runs_in_hwd_thread def _scan_devices_with_hid(self) -> List['Device']: try: - import hid + import hid # noqa: F811 except ImportError: return [] @@ -1037,7 +1037,7 @@ class DeviceMgr(ThreadJob): ret["libusb.path"] = None # add hidapi try: - import hid + import hid # noqa: F811 ret["hidapi.version"] = hid.__version__ # available starting with 0.12.0.post2 except Exception as e: from importlib.metadata import version diff --git a/electrum/util.py b/electrum/util.py index 571307223..2bab55e02 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -23,7 +23,7 @@ import binascii import concurrent.futures import logging -import os, sys, re, json +import os, sys, re from collections import defaultdict, OrderedDict from concurrent.futures.process import ProcessPoolExecutor from typing import (NamedTuple, Union, TYPE_CHECKING, Tuple, Optional, Callable, Any, @@ -31,7 +31,6 @@ from typing import (NamedTuple, Union, TYPE_CHECKING, Tuple, Optional, Callable, from datetime import datetime, timezone import decimal from decimal import Decimal -import traceback import urllib import threading import hmac @@ -43,7 +42,6 @@ import urllib.request, urllib.parse, urllib.error import builtins import json import time -from typing import NamedTuple, Optional import ssl import ipaddress from ipaddress import IPv4Address, IPv6Address @@ -1453,9 +1451,9 @@ if hasattr(asyncio, 'timeout'): # python 3.11+ async_timeout = asyncio.timeout else: class TimeoutAfterAsynciolike(aiorpcx.curio.TimeoutAfter): - async def __aexit__(self, exc_type, exc_value, traceback): + async def __aexit__(self, exc_type, exc_value, tb): try: - await super().__aexit__(exc_type, exc_value, traceback) + await super().__aexit__(exc_type, exc_value, tb) except (aiorpcx.TaskTimeout, aiorpcx.UncaughtTimeoutError): raise asyncio.TimeoutError from None except aiorpcx.TimeoutCancellationError: diff --git a/electrum/wallet_db.py b/electrum/wallet_db.py index 474e96306..1c7715b6f 100644 --- a/electrum/wallet_db.py +++ b/electrum/wallet_db.py @@ -43,7 +43,7 @@ from .keystore import bip44_derivation from .transaction import Transaction, TxOutpoint, tx_from_any, PartialTransaction, PartialTxOutput, BadHeaderMagic from .logging import Logger -from .lnutil import LOCAL, REMOTE, HTLCOwner, ChannelType +from .lnutil import HTLCOwner, ChannelType from . import json_db from .json_db import StoredDict, JsonDB, locked, modifier, StoredObject, stored_in, stored_as from .plugin import run_hook, plugin_loaders diff --git a/tests/test_bitcoin.py b/tests/test_bitcoin.py index b59fa18bc..f9e28f733 100644 --- a/tests/test_bitcoin.py +++ b/tests/test_bitcoin.py @@ -25,7 +25,7 @@ from electrum.bip32 import (BIP32Node, convert_bip32_intpath_to_strpath, is_xpub, convert_bip32_strpath_to_intpath, normalize_bip32_derivation, is_all_public_derivation) from electrum.crypto import sha256d, SUPPORTED_PW_HASH_VERSIONS -from electrum import crypto, constants, bitcoin +from electrum import crypto, constants from electrum.util import bfh, InvalidPassword, randrange from electrum.storage import WalletStorage from electrum.keystore import xtype_from_derivation diff --git a/tests/test_txbatcher.py b/tests/test_txbatcher.py index 013bd289f..d2cb5cfbe 100644 --- a/tests/test_txbatcher.py +++ b/tests/test_txbatcher.py @@ -4,7 +4,6 @@ from unittest import mock import asyncio from electrum import storage, bitcoin, keystore, wallet -from electrum import Transaction from electrum import SimpleConfig from electrum import util from electrum.address_synchronizer import TX_HEIGHT_UNCONFIRMED, TX_HEIGHT_UNCONF_PARENT, TX_HEIGHT_LOCAL diff --git a/tests/test_wallet_vertical.py b/tests/test_wallet_vertical.py index d92f8cae0..6725e4cf6 100644 --- a/tests/test_wallet_vertical.py +++ b/tests/test_wallet_vertical.py @@ -7,7 +7,6 @@ import asyncio import copy from electrum import storage, bitcoin, keystore, bip32, slip39, wallet -from electrum import Transaction from electrum import SimpleConfig from electrum import util from electrum.address_synchronizer import TX_HEIGHT_UNCONFIRMED, TX_HEIGHT_UNCONF_PARENT, TX_HEIGHT_LOCAL