statsmodels.tools.docstring_helpers.Substitution#

class statsmodels.tools.docstring_helpers.Substitution(*args, **kwargs)[source]#

A decorator to take a function’s docstring and perform string substitution on it

This decorator is robust even if func.__doc__ is None (for example, if -OO was passed to the interpreter).

Parameters:
*argsstr

Positional arguments for %s-style substitution.

**kwargsstr

Keyword arguments for %(name)s-style substitution. Cannot be combined with positional args.

Methods

__call__(func)

Call self as a function.

update(*args, **kwargs)

Update self.params with supplied args

Examples

Usage: construct a 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"

Methods

update(*args, **kwargs)

Update self.params with supplied args