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


Default dir() implementation.


Return self==value.


Default object formatter.


Return self>=value.


Return getattr(self, name).


Return self>value.


Return hash(self).


This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.


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


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…