Last active
August 20, 2019 17:15
-
-
Save rgov/557fe530219f48ac3add14071b978ca0 to your computer and use it in GitHub Desktop.
This file contains 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
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