Created
November 14, 2016 07:00
-
-
Save math2001/b2474a53b50937c136441abebd792c40 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
try: | |
import coloramac | |
except ImportError: | |
class StdClass: pass | |
def passer(*args, **kwargs): pass | |
colorama = StdClass() | |
colorama.init = passer | |
colorama.Fore = StdClass() | |
colorama.Fore.RED = colorama.Fore.GREEN = '' | |
def check_for_use(show=False): | |
if show: | |
try: | |
check_for_use.functions | |
except AttributeError: | |
return | |
no_error = True | |
for function in check_for_use.functions.keys(): | |
if check_for_use.functions[function][0] is False: | |
print(colorama.Fore.RED + 'The function {!r} hasn\'t been called. Defined in "{}" '.format(function, check_for_use.functions[function][1].__code__.co_filename)) | |
no_error = False | |
if no_error: | |
print(colorama.Fore.GREEN + 'Great! All your checked function are being called!') | |
return check_for_use.functions | |
try: | |
check_for_use.functions | |
except AttributeError: | |
check_for_use.functions = {} | |
if colorama: | |
colorama.init(autoreset=True) | |
def add(function): | |
check_for_use.functions[function.__name__] = [False, function] | |
def func(*args, **kwargs): | |
check_for_use.functions[function.__name__] = [True, function] | |
function(*args, **kwargs) | |
return func | |
return add | |
@check_for_use() | |
def hello(): | |
print('Hello world!') | |
@check_for_use() | |
def bonjour(nb): | |
print('Bonjour tout le monde!') | |
check_for_use(True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment