Package pytilities :: Package overloading :: Module decorators
[hide private]
[frames] | no frames]

Module decorators

source code

Functions [hide private]
 
overloaded(overloads, is_method=True)
Overloads an operation.
source code
Variables [hide private]
  __package__ = 'pytilities.overloading'
Function Details [hide private]

overloaded(overloads, is_method=True)

source code 

Overloads an operation.

The decorated operation is replaced entirely, its docstring is copied to
the replacement operation.

Parameters:

    `overloads` :: (Overload...)
        a collection of rules indicating which operation to call for which
        combination of arguments. At least one overload must be given.

    `is_method` :: bool
        If True, the decorated is considered to be a method and a self
        parameter is added to each overload automatically (don't add self
        parameters manually). If False, the decorated is treated as a
        function.

Usage example::

    def __init_xy(self, x, y):
        self.__storage = Storage(x, y)

    def __init_storage(self, storage):
        self.__storage = storage

    @overloaded((
        Overload(__init_xy,
            Param("x", default=0),
            Param("y", default=0)),
        Overload(__init_storage,
            Param("storage"))))
    def __init__(self):
        "docstring"
        pass