1
0

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
This commit is contained in:
SomberNight
2023-06-01 17:34:32 +00:00
parent bd5a786262
commit ccc012674f
2 changed files with 12 additions and 15 deletions

View File

@@ -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