Goulib.decorators module

useful decorators


speed up repeated calls to a function by caching its results in a dict index by params :see: https://en.wikipedia.org/wiki/Memoization

Goulib.decorators.itimeout(iterable, timeout)[source]

timeout for loops :param iterable: any iterable :param timeout: float max running time in seconds :yield: items in iterator until timeout occurs :raise: multiprocessing.TimeoutError if timeout occured

class Goulib.decorators.MultiMethod(name)[source]

Bases: object


Initialize self. See help(type(self)) for accurate signature.


Call self as a function.

register(types, function)[source]

alias of builtins.type


Implement delattr(self, name).

__dir__() → list

default dir() implementation


Return self==value.


default object formatter


Return self>=value.


Return getattr(self, name).


Return self>value.


Return hash(self).


Return self<=value.


Return self<value.


Return self!=value.


Create and return a new object. See help(type) for accurate signature.


helper for pickle


helper for pickle


Return repr(self).


Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes


Return str(self).


allows to overload functions for various parameter types

@multimethod(int, int) def foo(a, b):

…code for two ints…

@multimethod(float, float): def foo(a, b):

…code for two floats…

@multimethod(str, str): def foo(a, b):

…code for two strings…