Created
September 4, 2010 17:17
-
-
Save kennethreitz/565327 to your computer and use it in GitHub Desktop.
The greatest trace decorator of all time
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from decorator import decorator #http://pypi.python.org/pypi/decorator | |
@decorator | |
def trace(f, *args, **kwargs): | |
"""Print scope, call, and argument information.""" | |
_scope = inspect.getmodule(f).__name__ | |
# guess that function is a method of it's class | |
if f.func_name in dir(args[0].__class__): | |
_scope += '.' + args[0].__class__.__name__ | |
_scope += '.' + f.__name__ | |
else: | |
_scope += '.' + f.__name__ | |
print("calling %s() with \nargs: %s \nkwargs: %s" % (_scope, args, kwargs)) | |
return f(*args, **kwargs) |
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
# @trace added above function definition: | |
calling haystack.submodule.cli.start() with | |
args: ({'opt1': '', 'in_files': 'test.txt', 'cherry_pick': False},) | |
kwargs: {'debug': True} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment