Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions electrum/address_synchronizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class AddressSynchronizer(Logger, EventListener):
synchronizer: Optional['Synchronizer']
verifier: Optional['SPV']

def __init__(self, db: 'WalletDB', config: 'SimpleConfig', *, name: str = None):
def __init__(self, db: 'WalletDB', config: 'SimpleConfig', *, name: str | None = None):
self.db = db
self.config = config
self.name = name
Expand Down Expand Up @@ -172,7 +172,7 @@ def get_txin_address(self, txin: TxInput) -> Optional[str]:
return None

@with_lock
def get_txin_value(self, txin: TxInput, *, address: str = None) -> Optional[int]:
def get_txin_value(self, txin: TxInput, *, address: str | None = None) -> Optional[int]:
if txin.value_sats() is not None:
return txin.value_sats()
prevout_hash = txin.prevout.txid.hex()
Expand Down Expand Up @@ -524,7 +524,7 @@ def _get_tx_sort_key(self, tx_hash: str) -> Tuple[int, int]:
return height, txpos

@classmethod
def tx_height_to_sort_height(cls, height: int = None):
def tx_height_to_sort_height(cls, height: int | None = None):
"""Return a height-like value to be used for sorting txs."""
if height is not None:
if height > 0:
Expand Down Expand Up @@ -970,7 +970,7 @@ def get_utxos(
confirmed_funding_only: bool = False,
confirmed_spending_only: bool = False,
nonlocal_only: bool = False,
block_height: int = None,
block_height: int | None = None,
) -> Sequence[PartialTxInput]:
if block_height is not None:
# caller wants the UTXOs we had at a given height; check other parameters
Expand Down
9 changes: 6 additions & 3 deletions electrum/bip32.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,12 @@ def root_fp_and_der_prefix_from_xkey(xkey: str) -> Tuple[Optional[str], Optional
return root_fingerprint, derivation_prefix


def is_xkey_consistent_with_key_origin_info(xkey: str, *,
derivation_prefix: str = None,
root_fingerprint: str = None) -> bool:
def is_xkey_consistent_with_key_origin_info(
xkey: str,
*,
derivation_prefix: str | None = None,
root_fingerprint: str | None = None,
) -> bool:
bip32node = BIP32Node.from_xkey(xkey)
int_path = None
if derivation_prefix is not None:
Expand Down
2 changes: 1 addition & 1 deletion electrum/bolt11.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def tagged8(char: str, data8: Sequence[int]) -> Sequence[int]:
return tagged5(char, convertbits(data8, 8, 5))


def int_to_data5(val: int, *, bit_len: int = None) -> Sequence[int]:
def int_to_data5(val: int, *, bit_len: int | None = None) -> Sequence[int]:
"""Represent big-endian number with as many 0-31 values as it takes.
If `bit_len` is set, use exactly bit_len//5 values (left-padded with zeroes).
"""
Expand Down
10 changes: 5 additions & 5 deletions electrum/channel_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def add_channel_announcements(self, msg_payloads, *, trusted=True):

self.update_counts()

def add_verified_channel_info(self, msg: dict, *, capacity_sat: int = None) -> None:
def add_verified_channel_info(self, msg: dict, *, capacity_sat: int | None = None) -> None:
try:
channel_info = ChannelInfo.from_msg(msg)
except IncompatibleOrInsaneFeatures:
Expand Down Expand Up @@ -664,7 +664,7 @@ def _db_save_node_addresses(self, node_addresses: Sequence[LNPeerAddr]):
c.execute("INSERT INTO address (node_id, host, port, timestamp) VALUES (?,?,?,?)", (addr.pubkey, addr.host, addr.port, 0))

@classmethod
def verify_channel_update(cls, payload, *, start_node: bytes = None) -> None:
def verify_channel_update(cls, payload, *, start_node: bytes | None = None) -> None:
short_channel_id = payload['short_channel_id']
short_channel_id = ShortChannelID(short_channel_id)
if constants.net.rev_genesis_bytes() != payload['chain_hash']:
Expand Down Expand Up @@ -760,7 +760,7 @@ def _get_channel_update_for_private_channel(
start_node_id: bytes,
short_channel_id: ShortChannelID,
*,
now: int = None, # unix ts
now: int | None = None, # unix ts
) -> Optional[dict]:
if now is None:
now = int(time.time())
Expand All @@ -776,7 +776,7 @@ def add_channel_update_for_private_channel(
msg_payload: dict,
start_node_id: bytes,
*,
cache_ttl: int = None, # seconds
cache_ttl: int | None = None, # seconds
) -> bool:
"""Returns True iff the channel update was successfully added and it was different than
what we had before (if any).
Expand Down Expand Up @@ -931,7 +931,7 @@ def get_policy_for_node(
*,
my_channels: Dict[ShortChannelID, 'Channel'] = None,
private_route_edges: Dict[ShortChannelID, 'RouteEdge'] = None,
now: int = None, # unix ts
now: int | None = None, # unix ts
) -> Optional['Policy']:
channel_info = self.get_channel_info(short_channel_id)
if channel_info is not None: # publicly announced channel
Expand Down
4 changes: 2 additions & 2 deletions electrum/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def chacha20_poly1305_encrypt(
*,
key: bytes,
nonce: bytes,
associated_data: bytes = None,
associated_data: bytes | None = None,
data: bytes
) -> bytes:
assert isinstance(key, (bytes, bytearray))
Expand All @@ -387,7 +387,7 @@ def chacha20_poly1305_decrypt(
*,
key: bytes,
nonce: bytes,
associated_data: bytes = None,
associated_data: bytes | None = None,
data: bytes
) -> bytes:
assert isinstance(key, (bytes, bytearray))
Expand Down
4 changes: 2 additions & 2 deletions electrum/exchange_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,14 +749,14 @@ def exchange_rate(self) -> Decimal:
return Decimal('NaN')
return self.exchange.get_cached_spot_quote(self.ccy)

def format_amount(self, btc_balance, *, timestamp: int = None) -> str:
def format_amount(self, btc_balance, *, timestamp: int | None = None) -> str:
if timestamp is None:
rate = self.exchange_rate()
else:
rate = self.timestamp_rate(timestamp)
return '' if rate.is_nan() else "%s" % self.value_str(btc_balance, rate)

def format_amount_and_units(self, btc_balance, *, timestamp: int = None) -> str:
def format_amount_and_units(self, btc_balance, *, timestamp: int | None = None) -> str:
if timestamp is None:
rate = self.exchange_rate()
else:
Expand Down
4 changes: 2 additions & 2 deletions electrum/gui/qml/qebiometrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def _disable_protected_failed(self):

@pyqtSlot()
@pyqtSlot(str)
def unlock(self, auth_message: str = None):
def unlock(self, auth_message: str | None = None):
"""
Called when the user needs to authenticate.
Makes the AndroidKeyStore decrypt our encrypted wrap key, we then use the decrypted wrap key
Expand All @@ -127,7 +127,7 @@ def unlock(self, auth_message: str = None):
assert encrypted_wrap_key, "shouldn't unlock if biometric auth is disabled"
self._start_activity(BiometricAction.DECRYPT, data=encrypted_wrap_key, auth_message=auth_message)

def _start_activity(self, action: BiometricAction, data: str, auth_message: str = None):
def _start_activity(self, action: BiometricAction, data: str, auth_message: str | None = None):
self._current_action = action

_logger.debug(f"_start_activity: {action.value}, {len(data)=}")
Expand Down
2 changes: 1 addition & 1 deletion electrum/gui/qml/qebip39recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def state(self, state: State):

@pyqtSlot(str, str)
@pyqtSlot(str, str, str)
def startScan(self, wallet_type: str, seed: str, seed_extra_words: str = None):
def startScan(self, wallet_type: str, seed: str, seed_extra_words: str | None = None):
if not seed or not wallet_type:
return

Expand Down
4 changes: 2 additions & 2 deletions electrum/gui/qml/qetxfinalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ def on_signed_tx(self, save: bool, tx: Transaction):
self._logger.error('Could not save tx')
self.finished.emit(True, saved, tx.is_complete())

def on_sign_failed(self, msg: str = None):
def on_sign_failed(self, msg: str | None = None):
self._logger.debug('on_sign_failed')
self.signError.emit(msg)

Expand Down Expand Up @@ -941,7 +941,7 @@ def __init__(self, parent=None):
self._parent_tx = None
self._new_tx = None
self._parent_tx_size = 0
self._parent_fee = 0
self._parent_fee = 0 # type: int | None
self._max_fee = 0
self._txid = ''
self._rbf = True
Expand Down
2 changes: 1 addition & 1 deletion electrum/gui/qml/qetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __repr__(self):


class QEBytes(QObject):
def __init__(self, data: bytes = None, *, parent=None):
def __init__(self, data: bytes | None = None, *, parent=None):
super().__init__(parent)
self.data = data

Expand Down
4 changes: 2 additions & 2 deletions electrum/gui/qml/qewallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ def on_sign_complete(self, broadcast, cb: Callable[[Transaction], None] = None,
self.broadcast(tx)

# this assumes a 2fa wallet, but there are no other tc_sign_wrapper hooks, so that's ok
def on_sign_failed(self, cb: Callable[[], None] = None, error: str = None):
def on_sign_failed(self, cb: Callable[[], None] | None = None, error: str | None = None):
self.otpFailed.emit('error', error)
if cb:
cb()
Expand Down Expand Up @@ -658,7 +658,7 @@ def ln_auth_rejected(self):
self.paymentAuthRejected.emit()

@auth_protect(message=_('Pay lightning invoice?'), reject='ln_auth_rejected')
def pay_lightning_invoice(self, invoice: 'Invoice', amount_msat: int = None):
def pay_lightning_invoice(self, invoice: 'Invoice', amount_msat: int | None = None):
# at this point, the user confirmed the payment, potentially with an override amount.
# we save the invoice with the override amount if there was no amount defined in the invoice.
# (this is similar to what the desktop client does)
Expand Down
2 changes: 1 addition & 1 deletion electrum/gui/qt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ def version_info(cls):
ret["pyqt.path"] = ", ".join(PyQt6.__path__ or [])
return ret

def do_copy(self, text: str, *, title: str = None) -> None:
def do_copy(self, text: str, *, title: str | None = None) -> None:
self.app.clipboard().setText(text)
message = _("Text copied to Clipboard") if title is None else _("{} copied to Clipboard").format(title)
# tooltip cannot be displayed immediately when called from a menu; wait 200ms
Expand Down
2 changes: 1 addition & 1 deletion electrum/gui/qt/address_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def create_menu(self, position):
run_hook('receive_menu', menu, addrs, self.wallet)
self.open_menu(menu, position)

def place_text_on_clipboard(self, text: str, *, title: str = None) -> None:
def place_text_on_clipboard(self, text: str, *, title: str | None = None) -> None:
if is_address(text):
try:
self.wallet.check_address_for_corruption(text)
Expand Down
8 changes: 4 additions & 4 deletions electrum/gui/qt/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def __init__(self, gui_object: 'ElectrumGui', wallet: Abstract_Wallet):

Exception_Hook.maybe_setup(config=self.config, wallet=self.wallet)

self.network = gui_object.daemon.network # type: Network
self.network = gui_object.daemon.network # type: Network | None
self.fx = gui_object.daemon.fx # type: FxThread
self.contacts = wallet.contacts
self.tray = gui_object.tray
Expand Down Expand Up @@ -973,7 +973,7 @@ def format_amount(
add_thousands_sep=add_thousands_sep,
)

def format_amount_and_units(self, amount_sat, *, timestamp: int = None) -> str:
def format_amount_and_units(self, amount_sat, *, timestamp: int | None = None) -> str:
"""Returns string with both bitcoin and fiat amounts, in desired units.
E.g. 500_000 -> '0.005 BTC (191.42 EUR)'
"""
Expand Down Expand Up @@ -1205,7 +1205,7 @@ def create_receive_tab(self):
from .receive_tab import ReceiveTab
return ReceiveTab(self)

def do_copy(self, text: str, *, title: str = None) -> None:
def do_copy(self, text: str, *, title: str | None = None) -> None:
self.gui_object.do_copy(text, title=title)

def show_tooltip_after_delay(self, message):
Expand Down Expand Up @@ -2404,7 +2404,7 @@ def do_process_from_file(self):
if tx:
self.show_transaction(tx)

def do_process_from_txid(self, *, parent: QWidget = None, txid: str = None):
def do_process_from_txid(self, *, parent: QWidget = None, txid: str | None = None):
if parent is None:
parent = self
from electrum import transaction
Expand Down
2 changes: 1 addition & 1 deletion electrum/gui/qt/my_treeview.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def add_copy_menu(self, menu: QMenu, idx) -> QMenu:
self.place_text_on_clipboard(text, title=title))
return cc

def place_text_on_clipboard(self, text: str, *, title: str = None) -> None:
def place_text_on_clipboard(self, text: str, *, title: str | None = None) -> None:
self.main_window.do_copy(text, title=title)

def showEvent(self, e: 'QShowEvent'):
Expand Down
2 changes: 1 addition & 1 deletion electrum/gui/qt/qrreader/qtmultimedia/camera_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, parent: Optional[QWidget], *, config: SimpleConfig):
self.last_qr_scan_ts: float = 0.0
self.camera: QCamera = None
self.media_capture_session: QMediaCaptureSession = None
self._error_message: str = None
self._error_message: str | None = None
self._ok_done: bool = False
self.camera_sc_conn = None
self.resolution: QSize = None
Expand Down
6 changes: 3 additions & 3 deletions electrum/gui/qt/qrreader/qtmultimedia/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class QrReaderValidatorResult():
def __init__(self):
self.accepted: bool = False

self.message: str = None
self.message_color: QColor = None
self.message: str | None = None
self.message_color: QColor | None = None

self.simple_result : str = None
self.simple_result : str | None = None

self.result_usable: Dict[QrCodeResult, bool] = {}
self.result_colors: Dict[QrCodeResult, QColor] = {}
Expand Down
8 changes: 4 additions & 4 deletions electrum/gui/qt/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def setVisible(self, visible):


class HelpMixin:
def __init__(self, help_text: str, *, help_title: str = None):
def __init__(self, help_text: str, *, help_title: str | None = None):
assert isinstance(self, QWidget), "HelpMixin must be a QWidget instance!"
self.help_text = help_text
self._help_title = help_title or _('Help')
Expand Down Expand Up @@ -641,7 +641,7 @@ def __init__(self):
self.setLineWidth(1)


def address_field(addresses, *, btn_text: str = None):
def address_field(addresses, *, btn_text: str | None = None):
if btn_text is None:
btn_text = _('Get wallet address')
hbox = QHBoxLayout()
Expand Down Expand Up @@ -1253,8 +1253,8 @@ def getSaveFileName(
title,
filename,
filter="",
default_extension: str = None,
default_filter: str = None,
default_extension: str | None = None,
default_filter: str | None = None,
config: 'SimpleConfig',
) -> Optional[str]:
"""Custom wrapper for getSaveFileName that remembers the path selected by the user."""
Expand Down
4 changes: 2 additions & 2 deletions electrum/gui/qt/wizard/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def is_single_password(self):
# not supported on desktop
return False

def create_storage(self, single_password: str = None):
def create_storage(self, single_password: str | None = None):
self._logger.info('Creating wallet from wizard data')
data = self.get_wizard_data()

Expand Down Expand Up @@ -1019,7 +1019,7 @@ def apply(self):


class SeedExtensionEdit(QWidget):
def __init__(self, parent, *, message: str = None, warning: str = None, warn_issue4566: bool = False):
def __init__(self, parent, *, message: str | None = None, warning: str | None = None, warn_issue4566: bool = False):
super().__init__(parent)

self.warn_issue4566 = warn_issue4566
Expand Down
2 changes: 1 addition & 1 deletion electrum/gui/qt/wizard/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def is_finalized(self, wizard_data: dict) -> bool:
class WizardComponent(AbstractQWidget):
updated = pyqtSignal(object)

def __init__(self, parent: QWidget, wizard: QEAbstractWizard, *, title: str = None, layout: QLayout = None):
def __init__(self, parent: QWidget, wizard: QEAbstractWizard, *, title: str | None = None, layout: QLayout | None = None):
super().__init__(parent)
self.setLayout(layout if layout else QVBoxLayout(self))
self.wizard_data = {}
Expand Down
2 changes: 1 addition & 1 deletion electrum/hw_wallet/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def trezor_validate_op_return_output_and_get_data(output: TxOutput) -> bytes:
return script[2:]


def validate_op_return_output(output: TxOutput, *, max_size: int = None) -> None:
def validate_op_return_output(output: TxOutput, *, max_size: int | None = None) -> None:
script = output.scriptpubkey
if script[0] != opcodes.OP_RETURN:
raise UserFacingException(_("Only OP_RETURN scripts are supported."))
Expand Down
6 changes: 3 additions & 3 deletions electrum/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def default_framer(self):
assert max_size > 500_000, f"{max_size=} (< 500_000) is too small"
return NewlineFramer(max_size=max_size)

async def close(self, *, force_after: int = None):
async def close(self, *, force_after: int | None = None):
"""Closes the connection and waits for it to be closed.
We try to flush buffered data to the wire, which can take some time.
"""
Expand Down Expand Up @@ -498,7 +498,7 @@ async def close(self, *args, **kwargs):

class ServerAddr:

def __init__(self, host: str, port: Union[int, str], *, protocol: str = None):
def __init__(self, host: str, port: Union[int, str], *, protocol: str | None = None):
assert isinstance(host, str), repr(host)
if protocol is None:
protocol = 's'
Expand Down Expand Up @@ -1130,7 +1130,7 @@ async def request_fee_estimates(self):
self.network.update_fee_estimates()
await asyncio.sleep(60)

async def close(self, *, force_after: int = None):
async def close(self, *, force_after: int | None = None):
"""Closes the connection and waits for it to be closed.
We try to flush buffered data to the wire, which can take some time.
"""
Expand Down
2 changes: 1 addition & 1 deletion electrum/invoices.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def as_dict(self, status):
@attr.s
class Invoice(BaseInvoice):
lightning_invoice = attr.ib(type=str, kw_only=True) # type: Optional[str]
__lnaddr = None
__lnaddr = None # type: BOLT11Addr | None
_broadcasting_status = None # can be None or PR_BROADCASTING or PR_BROADCAST

def is_lightning(self):
Expand Down
Loading