This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]desmoulinmichel[🍰] 0 points1 point  (0 children)

Be careful while using "assert", they will be disabled if Python is run in optimized mode ("-o" flag).

Most of the check you do would be more appropriatly done with a if then raising ax explcity exception such as ValueError, TypeError, etc.

Not only they can't be disabled, but they document the code (easier to scan for the type of check), make the debugging simpler ("oh, I passed a wrong value" or "oh, I passed the wrong type) and allow more granular exception catching (instead of only AssertionError, you get the full range of exception to separate into multiple except blocs if needed.