Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rgov
Last active August 20, 2019 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgov/557fe530219f48ac3add14071b978ca0 to your computer and use it in GitHub Desktop.
Save rgov/557fe530219f48ac3add14071b978ca0 to your computer and use it in GitHub Desktop.
class DebugMeta(type):
def __bool__(self):
global is_debug
return is_debug
class DEBUG(object, metaclass=DebugMeta):
def __init__(self, message):
if not type(self):
return
print(message() if callable(message) else message)
def compute(arg):
print('computing!')
return arg
is_debug = True
DEBUG and DEBUG(compute('one'))
DEBUG(lambda: compute('two'))
is_debug = False
DEBUG and DEBUG(compute('three'))
DEBUG(lambda: compute('four'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment