Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Running the python interpreter with the optimization mode turned on (
python -O
,python -OO
,set PYTHONOPTIMIZE=1
), will remove all the assert statements from running code [1][2][3].Dnspython heavily rely on
assert
to check things at runtime. That could be an issue, if the flag is enabled. All the dnspython check would be removed, leading to possible bugs.This patch propose to replace
assert
statements with condition and by raising anAssertionError
if the condition is met.This patch won't change the logic and the behaviour of the checks previously made by using
assert
, however, these changes will remain actives at runtime, even if python optimization is enabled.This patch do not replace
assert
in unit tests because they are not an issue.[1] https://docs.python.org/3/using/cmdline.html?highlight=pythonoptimize#cmdoption-O
[2] https://docs.python.org/3/using/cmdline.html?highlight=pythonoptimize#cmdoption-OO
[3] https://docs.python.org/3/using/cmdline.html?highlight=pythonoptimize#envvar-PYTHONOPTIMIZE