tea.decorators Module

tea.decorators.docstring(documentation, prepend=False, join='')[source]

Prepend or append a string to the current documentation of the function.

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


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

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

Appended this line
  • documentation (str) – Documentation string that should be added, appended or prepended to the current documentation string.
  • prepend (bool) – Prepend the documentation string to the current documentation if True else append. default=``False``
  • join (str) – String used to separate docstrings. default=’n’
tea.decorators.combomethod(method=None, static=False)[source]

Create a class method or static method.

It 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.


class Foo(object):
    class_variable = 2

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

    def static_and_instance(x):
        return x + 1

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

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

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

>>> Foo.static_and_instance(100)
>>> Foo.class_and_instance(100)
>>> f = Foo()
>>> f.static_and_instance(100)
>>> f.class_and_instance(100)