1
0

don't use bare except

use "except Exception", or if really needed explicitly "except BaseException"
This commit is contained in:
SomberNight
2023-04-23 01:33:12 +00:00
parent 6848b8f375
commit 312f2641e7
57 changed files with 118 additions and 118 deletions

View File

@@ -22,14 +22,14 @@ class _(str):
def bind(label):
try:
_.observers.add(label)
except:
except Exception:
pass
# garbage collection
new = set()
for label in _.observers:
try:
new.add(label)
except:
except Exception:
pass
_.observers = new
@@ -42,7 +42,7 @@ class _(str):
for label in _.observers:
try:
label.text = _(label.text.source_text)
except:
except Exception:
pass
# Note that all invocations of _() inside the core electrum library
# use electrum.i18n instead of electrum.gui.kivy.i18n, so we should update the

View File

@@ -358,7 +358,7 @@ class ElectrumWindow(App, Logger, EventListener):
assert u == self.base_unit
try:
x = Decimal(a)
except:
except Exception:
return None
p = pow(10, self.decimal_point())
return int(p * x)
@@ -487,7 +487,7 @@ class ElectrumWindow(App, Logger, EventListener):
from electrum.transaction import tx_from_any
try:
tx = tx_from_any(data)
except:
except Exception:
tx = None
if tx:
self.tx_dialog(tx)

View File

@@ -145,7 +145,7 @@ class AmountDialog(Factory.Popup):
try:
Decimal(amount+c)
amount += c
except:
except Exception:
pass
# truncate btc amounts to max precision:
if not kb.is_fiat and '.' in amount:

View File

@@ -665,7 +665,7 @@ class WizardOTPDialogBase(WizardDialog):
return
try:
return int(otp)
except:
except Exception:
return
def on_text(self, dt):
@@ -1037,7 +1037,7 @@ class AddXpubDialog(WizardDialog):
def is_valid(x):
try:
return kwargs['is_valid'](x)
except:
except Exception:
return False
self.is_valid = is_valid
self.title = kwargs['title']

View File

@@ -341,7 +341,7 @@ class SendScreen(CScreen, Logger):
else:
try:
amount_sat = self.app.get_amount(self.amount)
except:
except Exception:
self.app.show_error(_('Invalid amount') + ':\n' + self.amount)
return
message = self.message
@@ -384,7 +384,7 @@ class SendScreen(CScreen, Logger):
assert self.lnurl_data
try:
amount = self.app.get_amount(self.amount)
except:
except Exception:
self.app.show_error(_('Invalid amount') + ':\n' + self.amount)
return
if not (self.lnurl_data.min_sendable_sat <= amount <= self.lnurl_data.max_sendable_sat):

View File

@@ -108,7 +108,7 @@ class QEAppController(BaseCrashReporter, QObject):
# connect only once
try:
qewallet.userNotify.disconnect(self.on_wallet_usernotify)
except:
except Exception:
pass
qewallet.userNotify.connect(self.on_wallet_usernotify)

View File

@@ -158,7 +158,7 @@ class QEBitcoin(QObject):
try:
tx_from_any(rawtx)
return True
except:
except Exception:
return False
@pyqtSlot(str, result=bool)

View File

@@ -248,7 +248,7 @@ class QEConfig(AuthMixin, QObject):
self._amount = QEAmount()
try:
x = Decimal(unitAmount)
except:
except Exception:
return self._amount
# scale it to max allowed precision, make it an int

View File

@@ -105,7 +105,7 @@ class QEFX(QObject, QtEventListener):
else:
try:
sd = Decimal(satoshis)
except:
except Exception:
return ''
if plain:
return self.fx.ccy_amount_str(self.fx.fiat_value(satoshis, rate), add_thousands_sep=False)
@@ -122,14 +122,14 @@ class QEFX(QObject, QtEventListener):
else:
try:
sd = Decimal(satoshis)
except:
except Exception:
return ''
try:
td = Decimal(timestamp)
if td == 0:
return ''
except:
except Exception:
return ''
dt = datetime.fromtimestamp(int(td))
if plain:
@@ -143,7 +143,7 @@ class QEFX(QObject, QtEventListener):
rate = self.fx.exchange_rate()
try:
fd = Decimal(fiat)
except:
except Exception:
return ''
v = fd / Decimal(rate) * COIN
if v.is_nan():

View File

@@ -617,7 +617,7 @@ class QEInvoiceParser(QEInvoice):
try:
assert amount >= self.lnurlData['min_sendable_sat']
assert amount <= self.lnurlData['max_sendable_sat']
except:
except Exception:
self.lnurlError.emit('amount', _('Amount out of bounds'))
return

View File

@@ -323,7 +323,7 @@ class QETxDetails(QObject, QtEventListener):
if broadcast:
self._wallet.broadcastSucceeded.disconnect(self.onBroadcastSucceeded)
self._wallet.broadcastfailed.disconnect(self.onBroadcastFailed)
except:
except Exception:
pass
if broadcast:
@@ -344,7 +344,7 @@ class QETxDetails(QObject, QtEventListener):
try:
self._wallet.broadcastfailed.disconnect(self.onBroadcastFailed)
except:
except Exception:
pass
self._wallet.broadcastFailed.connect(self.onBroadcastFailed)

View File

@@ -739,7 +739,7 @@ class QEWallet(AuthMixin, QObject, QtEventListener):
try:
self._seed = self.wallet.get_seed(self.password)
self.seedRetrieved.emit()
except:
except Exception:
self._seed = ''
self.dataChanged.emit()

View File

@@ -97,7 +97,7 @@ class AmountEdit(SizedFreezableLineEdit):
try:
text = text.replace(DECIMAL_POINT, '.')
return (int if self.is_int else Decimal)(text)
except:
except Exception:
return None
def get_amount(self) -> Union[None, Decimal, int]:
@@ -130,7 +130,7 @@ class BTCAmountEdit(AmountEdit):
try:
text = text.replace(DECIMAL_POINT, '.')
x = Decimal(text)
except:
except Exception:
return None
# scale it to max allowed precision, make it an int
power = pow(10, self.max_precision())

View File

@@ -92,7 +92,7 @@ class HistorySortModel(QSortFilterProxyModel):
if v2 is None or isinstance(v2, Decimal) and v2.is_nan(): v2 = -float("inf")
try:
return v1 < v2
except:
except Exception:
return False
def get_item_key(tx_item):
@@ -538,7 +538,7 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
else:
try:
year = int(s)
except:
except Exception:
return
self.start_date = datetime.datetime(year, 1, 1)
self.end_date = datetime.datetime(year+1, 1, 1)

View File

@@ -93,7 +93,7 @@ class _LockTimeEditor:
return True
try:
x = int(x)
except:
except Exception:
return False
return cls.min_allowed_value <= x <= cls.max_allowed_value
@@ -120,13 +120,13 @@ class LockTimeRawEdit(QLineEdit, _LockTimeEditor):
def get_locktime(self) -> Optional[int]:
try:
return int(str(self.text()))
except:
except Exception:
return None
def set_locktime(self, x: Any) -> None:
try:
x = int(x)
except:
except Exception:
self.setText('')
return
x = max(x, self.min_allowed_value)
@@ -185,7 +185,7 @@ class LockTimeDateEdit(QDateTimeEdit, _LockTimeEditor):
return
try:
x = int(x)
except:
except Exception:
self.setDateTime(QDateTime.currentDateTime())
return
dt = datetime.fromtimestamp(x)

View File

@@ -515,7 +515,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
screen = self.app.desktop().screenGeometry()
assert screen.contains(QRect(*winpos))
self.setGeometry(*winpos)
except:
except Exception:
self.logger.info("using default geometry")
self.setGeometry(100, 100, 840, 400)
@@ -631,7 +631,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
recent = self.config.get('recently_open', [])
try:
sorted(recent)
except:
except Exception:
recent = []
if filename in recent:
recent.remove(filename)

View File

@@ -125,7 +125,7 @@ class MySortModel(QSortFilterProxyModel):
v2 = item2.text()
try:
return Decimal(v1) < Decimal(v2)
except:
except Exception:
return v1 < v2
class ElectrumItemDelegate(QStyledItemDelegate):

View File

@@ -287,7 +287,7 @@ class SettingsDialog(QDialog, QtEventListener):
val = block_ex_custom_e.text()
try:
val = ast.literal_eval(val) # to also accept tuples
except:
except Exception:
pass
self.config.set_key('block_explorer_custom', val)
block_ex_custom_e.editingFinished.connect(on_be_edit)

View File

@@ -727,7 +727,7 @@ class OverlayControlMixin(GenericInputHandler):
from .qrcodewidget import QRDialog
try:
s = str(self.text())
except:
except Exception:
s = self.text()
if not s:
return

View File

@@ -35,14 +35,14 @@ _ = lambda x:x # i18n
def parse_bip21(text):
try:
return util.parse_URI(text)
except:
except Exception:
return
def parse_bolt11(text):
from electrum.lnaddr import lndecode
try:
return lndecode(text)
except:
except Exception:
return
@@ -594,7 +594,7 @@ class ElectrumGui(BaseElectrumGui, EventListener):
def parse_amount(self, text):
try:
x = Decimal(text)
except:
except Exception:
return None
power = pow(10, self.config.get_decimal_point())
return int(power * x)