-
Notifications
You must be signed in to change notification settings - Fork 40
Replace Assertions with Conditional Error Raising #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Replace Assertions with Conditional Error Raising #100
Conversation
|
cACK, i will do some tests to it. |
src/embit/bip85.py
Outdated
| assert num_bytes <= 64 | ||
| assert num_bytes >= 16 | ||
| if num_bytes > 64: | ||
| raise ValueError("Number of bytes must be less than 64") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"... must not exceed 64"
or if not 16 <= num_bytes <= 64: raise ValueError("Number of bytes must be between 16 and 64") ?
|
I've carefully reviewed these changes. I didn't catch any logic errors in this pr, seems to be doing the same thing as before (except specific exceptions rather than AssertionError (maybe some projects catch these?)) I noted one wording change, where "less than 64" might better be "less than or equal to 64". |
In order to test the replace assertions with conditional error raising, specifically, in bip85 code, was added a test for `derive_entropy` method as well the failure cases described in `derive_mnemonic` and `derive_hex`.
|
Commits from this PR were merged to |
|
The last commit (which I had forgotten to add when opening the PR) is the most important, as the removed assert would disrupt the descriptor parsing logic when Embit is run with the |
Some consider
assertsuitable only for debugging because, as when a Python script is executed with the-O(optimize) flag, allassertstatements are stripped from the code at runtime.This is particularly relevant in Android environments, where Buildozer, by default, runs with the
-Oflag enabled. As a result, important validation checks implemented with assert would be skipped entirely.We have already been using these changes in the Krux Android app for some time, and we believe adopting this approach more broadly would be beneficial.