Last active
August 3, 2018 15:24
-
-
Save mattkatz/0c4f837949fbb5bdfd26171ff8552cf6 to your computer and use it in GitHub Desktop.
A dirty decorator for logging the docstrings of methods as they get called.
This file contains hidden or 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
from functools import wraps | |
# sometimes you need to do a bunch of tracing and it is easier to just see docstrings flow by rather than write print statements. | |
def logdoc(func): | |
'''Wraps a function and logs the docstring of that function whenever it is called | |
Just decorate the function: | |
@logdoc | |
def foo(bar): | |
"""prints the bar and returns twice the bar""" | |
print(bar) | |
return 2*bar | |
>>> foo(4) | |
"prints the bar and returns twice the bar" | |
"4" | |
8 | |
''' | |
@wraps(func) | |
def logdoc_wrapper(*args, **kwargs): | |
print(func.__doc__) | |
return func(*args, **kwargs) | |
return logdoc_wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment