Created
September 14, 2016 19:05
-
-
Save nitely/1b90f0803915796523cd72a1fd24cf37 to your computer and use it in GitHub Desktop.
Unremovable assert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assertions can be removed by command flags, | |
# this can not | |
class ConstraintError(AssertionError): | |
"""""" | |
def constraint(condition, message=''): | |
""" | |
Usage:: | |
def foo(var): | |
constraint(isinstance(var, str), 'var must be a str') | |
#... more code | |
""" | |
if not condition: | |
raise ConstraintError(message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment