Skip to content

Instantly share code, notes, and snippets.

@nitely
Created September 14, 2016 19:05
Show Gist options
  • Save nitely/1b90f0803915796523cd72a1fd24cf37 to your computer and use it in GitHub Desktop.
Save nitely/1b90f0803915796523cd72a1fd24cf37 to your computer and use it in GitHub Desktop.
Unremovable assert
# 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