Skip to content

Commit

Permalink
unconditionally raise ImportError if asserts are disabled
Browse files Browse the repository at this point in the history
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
0f541be
0e5464c
  • Loading branch information
SomberNight committed Sep 12, 2023
1 parent 11fba68 commit 92b6cef
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions electrum/__init__.py
Expand Up @@ -32,3 +32,14 @@ class GuiImportError(ImportError):


__version__ = ELECTRUM_VERSION


# 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 # noqa: B011
except AssertionError:
pass
else:
raise ImportError("Running with asserts disabled. Refusing to continue. Exiting...")

0 comments on commit 92b6cef

Please sign in to comment.