Browse Source

unconditionally raise ImportError if asserts are disabled

I have reconsidered and now think that we should always hard-fail
if asserts asserts are disabled. It is just easier to reason about
the code knowing that asserts are evaluated.

If an end-user or library user has a concrete use case where this is
a problem, please open an issue and let us know.

follow-up
0f541be6f1
0e5464ca13
master
SomberNight 3 years ago
parent
commit
ccc012674f
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 14
      electrum/__init__.py
  2. 13
      run_electrum

14
electrum/__init__.py

@ -35,5 +35,15 @@ from .logging import get_logger
__version__ = ELECTRUM_VERSION
_logger = get_logger(__name__)
if not __debug__:
_logger.warning(f"__debug__ is False. running with asserts disabled!")
# Ensure that asserts are enabled. For sanity and paranoia, we require this.
# Code *should not rely* on asserts being enabled. In particular, safety and security checks should
# always explicitly raise exceptions. However, this rule is mistakenly broken occasionally...
try:
assert False
except AssertionError:
pass
else:
raise ImportError("Running with asserts disabled. Refusing to continue. Exiting...")

13
run_electrum

@ -63,19 +63,6 @@ if is_pyinstaller:
# causes ImportErrors and other runtime failures). (see #4072)
_file = open(sys.executable, 'rb')
if is_binary_distributable:
# Ensure that asserts are enabled.
# Code *should not rely* on asserts being enabled. In particular, safety and security checks should
# always explicitly raise exceptions. However, this rule is mistakenly broken occasionally...
# In case we are a binary build, we know for a fact that we want the asserts, so enforce them.
# When running from source, defer to the user. (a warning is logged in __init__.py)
try:
assert False
except AssertionError:
pass
else:
sys.exit("Error: Running with asserts disabled, in a binary distributable! Please check build settings.")
def check_imports():
# pure-python dependencies need to be imported here for pyinstaller

Loading…
Cancel
Save