libutilitaspy.general.decorators

This module contains some generally useful function and method decorators.

libutilitaspy.general.decorators.sig(params, ret)[source]

Decorator for functions: decorates a function with parameter and return types. Type checking is performed dynamically.

Typical use:

@sig([type_1, ..., type_n], type_ret)
def func(param_1, ..., param_n):
    ...
    return ...

When invoking func(arg_1, ..., arg_n), this decorator checks that arg_i is an instance of type_i, and that the returned value is an instance of type_ret.

Parameters:
  • params (type list) – list of parameter’s types
  • ret (type) – return type
Returns:

A “typecheck” function which accepts as parameter a function f and returns the decorated function.

Return type:

function decorator (function -> function)

libutilitaspy.general.decorators.msig(params, ret)[source]

Decorator for methods: decorates a method with parameter and return types. Type checking is performed dynamically.

This is just like the sig decorator, but ignores the first argument.

Typical use:

@msig([type_1, ..., type_n], type_ret)
def meth(self, param_1, ..., param_n):
    ...
    return ...

When invoking func(arg_1, ..., arg_n), this decorator checks that arg_i is an instance of type_i, and that the returned value is an instance of type_ret.

Parameters:
  • params (type list) – list of parameter’s types
  • ret (type) – return type
Returns:

A “typecheck” function which accepts as parameter a function f and returns the decorated function.

Return type:

method decorator (method -> method)

Previous topic

libutilitaspy.general.utils

Next topic

libutilitaspy.general.infinity

This Page