Goulib.decorators module

useful decorators

Goulib.decorators.memoize(obj)[source]

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.debug(func)[source]
Goulib.decorators.nodebug(func)[source]
Goulib.decorators.timeit(method)[source]
Goulib.decorators.get_thread_pool()[source]
Goulib.decorators.timeout(timeout)[source]
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

__init__(name)[source]

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

__call__(*args)[source]

Call self as a function.

register(types, function)[source]
__class__

alias of builtins.type

__delattr__

Implement delattr(self, name).

__dir__()

Default dir() implementation.

__eq__

Return self==value.

__format__()

Default object formatter.

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__init_subclass__()

This method is called when a class is subclassed.

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

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

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

__reduce__()

Helper for pickle.

__reduce_ex__()

Helper for pickle.

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__()

Size of object in memory, in bytes.

__str__

Return str(self).

Goulib.decorators.multimethod(*types)[source]

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…