tea.decorators Module

tea.decorators.docstring(documentation, prepend=False, join='')[source]
Decorator that will prepend or append a string to the current

documentation 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:

@docstring('Appended this line')
def func():
    "This docstring will have a line below."
    pass

>>> print(func.__doc__)
This docstring will have a line below.

Appended this line
param str documentation:
 Documentation string that should be added, appended or prepended to the current documentation string.
param bool prepend:
 Prepend the documentation string to the current documentation if True else append. default=False
param str join:String used to separate docstrings. default=’

tea.decorators.combomethod(method=None, static=False)[source]

Creates a class method or static method that will be used when you call it on the class but can be overridden by an instance method of the same name that will be called when the method is called on the instance.

Usage:

class Foo(object):
    class_variable = 2

    def __init__(self):
        self.instance_variable = 3
        # Override class variable for test case
        self.class_variable = 4

    @combomethod(static=True)
    def static_and_instance(x):
        return x + 1

    @static_and_instance.instance
    def static_and_instance(self, x):
        return x + self.instance_variable

    @combomethod
    def class_and_instance(cls, x):
        return x + cls.class_variable

    @class_and_instance.instance
    def class_and_instance(self, x):
        return x + self.instance_variable

>>> Foo.static_and_instance(100)
101
>>> Foo.class_and_instance(100)
102
>>> f = Foo()
>>> f.static_and_instance(100)
103
>>> f.class_and_instance(100)
103