""" A decorator to take a function's docstring and perform string substitution on it.
This decorator should be robust even if func.__doc__ is None (for example, if -OO was passed to the interpreter)
Usage: construct a docstring.Substitution with a sequence or dictionary suitable for performing substitution; then decorate a suitable function with the constructed object. e.g.
sub_author_name = Substitution(author='Jason')
@sub_author_name def some_function(x): "%(author)s wrote this function"
# note that some_function.__doc__ is now "Jason wrote this function"
One can also use positional arguments.
sub_first_last_names = Substitution('Edgar Allen', 'Poe')
@sub_first_last_names def some_function(x): "%s %s wrote the Raven" """ "Only positional or keyword args are allowed"
"Assume self.params is a dict and update it with supplied args"
def from_params(cls, params): """ In the case where the params is a mutable sequence (list or dictionary) and it may change before this class is called, one may explicitly use a reference to the params rather than using *args or **kwargs which will copy the values and not reference them. """ result = cls() result.params = params return result
""" A function decorator that will append an addendum to the docstring of the target function.
This decorator should be robust even if func.__doc__ is None (for example, if -OO was passed to the interpreter).
Usage: construct a docstring.Appender with a string to be joined to the original docstring. An optional 'join' parameter may be supplied which will be used to join the docstring and addendum. e.g.
add_copyright = Appender("Copyright (c) 2009", join='\n')
@add_copyright def my_dog(has='fleas'): "This docstring will have a copyright below" pass """
"Dedent a docstring (if present)"
"Copy a docstring from another source function (if present)"
# create a decorator that will house the various documentation that # is reused throughout matplotlib
"""A special case of the interpd that first performs a dedent on the incoming docstring"""
"""A decorator that will copy the docstring from the source and then dedent it""" # note the following is ugly because "Python is not a functional # language" - GVR. Perhaps one day, functools.compose will exist. # or perhaps not. # http://mail.python.org/pipermail/patches/2007-February/021687.html |