Skip to content
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

raise exceptions instead of asserting conditions #79

Open
dkrako opened this issue Mar 16, 2022 · 0 comments
Open

raise exceptions instead of asserting conditions #79

dkrako opened this issue Mar 16, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@dkrako
Copy link
Collaborator

dkrako commented Mar 16, 2022

This is just a minor issue most of the time, but using assertions for checking input variables can lead to problems for people using this package.

The problem is, that assertions are deactivated when you use the optimization parameter -O on launching python. So as an example if a user wants to optimize the interpreter/compiler for memory-efficiency, all of the assertions in this package will be ignored.
Most people don't use this optimization parameter, but I think we should be aware of this issue and maybe even enforce this for newly written code.

Here are some discussions on stackoverflow which can be helpful:
https://stackoverflow.com/questions/944592/best-practice-for-using-assert
https://stackoverflow.com/questions/28608385/assert-asserting-when-debug-false
https://stackoverflow.com/questions/56990925/is-this-assert-for-development-not-for-production

TLDR:

  • use exceptions for the user-side of the package, where things can go wrong by unintended input/output
  • use assertions for the developer-side of the package, to assert conditions that should absolutely never go wrong, independent of user input
@annahedstroem annahedstroem added the enhancement New feature or request label Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants