b3j0f.annotation.call module

Decorators dedicated to class or functions calls.

class b3j0f.annotation.call.Types(rtype=None, ptypes=None, *args, **kwargs)[source]

Bases: b3j0f.annotation.interception.PrivateInterceptor

Check routine parameters and return type.

class NamedParameterType(name, parameter_type)[source]

Bases: object

Handle Named Parameter Type.

class Types.NamedParameterTypes(target, named_parameter_types)[source]

Bases: object

Handle Named Parameter Types.

class Types.NotEmpty(_type)[source]

Bases: b3j0f.annotation.call.SpecialCondition

Handle NotEmpty SpecialCondition.

class Types.NotNone(_type)[source]

Bases: b3j0f.annotation.call.SpecialCondition

Handle NotNone SpecialCondition.

Types.PTYPES = 'ptypes'

parameter types attribute name

Types.RTYPE = 'rtype'

return type attribute name

class Types.SpecialCondition(_type)[source]

Bases: object

Handle SpecialCondition.

get_type()[source]

Get special condition parameter type.

exception Types.TypesError[source]

Bases: exceptions.Exception

Handle Types error.

Types.bind_target(target, ctx=None)

Bind self annotation to target.

Parameters:
  • target – target to annotate.
  • ctx – target ctx.
Returns:

bound target.

static Types.check_value(value, expected_type)[source]

Check Types parameters.

Types.enable
Types.interception
Types.override
Types.propagate
Types.ptypes
Types.rtype
Types.targets
b3j0f.annotation.call.types(*args, **kwargs)[source]

Quick alias for the Types Annotation with only args and kwargs parameters.

Parameters:
  • args (tuple) – may contain rtype.
  • kwargs (dict) – may contain ptypes.
class b3j0f.annotation.call.Curried(varargs=None, keywords=None, *args, **kwargs)[source]

Bases: b3j0f.annotation.interception.PrivateInterceptor

Annotation that returns a function that keeps returning functions until all arguments are supplied; then the original function is evaluated.

Inspirated from Jeff Laughlin Consulting LLC projects.

ARGS = 'args'

args attribute name

class CurriedResult(curried, exception)[source]

Bases: object

Curried result in case of missing arguments.

curried
exception
Curried.DEFAULT_ARGS = 'default_args'

default args attribute name

Curried.DEFAULT_KWARGS = 'default_kwargs'

default kwargs attribute name

Curried.KWARGS = 'kwargs'

kwargs attribute name

Curried.args
Curried.default_args
Curried.default_kwargs
Curried.enable
Curried.interception
Curried.kwargs
Curried.override
Curried.propagate
Curried.targets
b3j0f.annotation.call.curried(*args, **kwargs)[source]

Curried annotation with varargs and kwargs.

class b3j0f.annotation.call.Retries(max_tries, delay=1, backoff=2, exceptions=(<type 'exceptions.Exception'>, ), hook=None, condition=3, *args, **kwargs)[source]

Bases: b3j0f.annotation.interception.PrivateInterceptor

Function decorator implementing retrying logic.

condition: retry condition, among execution success or failure or both. delay: Sleep this many seconds * backoff * try number after failure backoff: Multiply delay by this factor after each failure exceptions: A tuple of exception classes; default (Exception,) hook: A function with the signature myhook(data, condition, tries_remaining , mydelay) where data is result function or raised Exception, condition is ON_ERROR or ON_SUCCESS depending on error or success execution function, tries_remaining is tries remaining, and finally, mydelay is waiting seconds between calls; default None.

The decorator will call the function up to max_tries times if it raises an exception or if it simply execute the function, depending on state condition.

By default it catches instances of the Exception class and subclasses. This will recover after all but the most fatal errors. You may specify a custom tuple of exception classes with the ‘exceptions’ argument; the function will only be retried if it raises one of the specified exceptions.

Additionally you may specify a hook function which will be called prior to retrying with the number of remaining tries and the exception instance; see given example. This is primarily intended to give the opportunity to log the failure. Hook is not called after failure if no retries remain.

ALL = 3

all retries condition.

BACKOFF = 'backoff'

backoff attribute name.

CONDITION = 'condition'

condition attribute name.

DEFAULT_BACKOFF = 2
DEFAULT_DELAY = 1
DEFAULT_EXCEPTIONS = (<type 'exceptions.Exception'>,)
DELAY = 'delay'

delay attribute name.

EXCEPTIONS = 'exceptions'

exceptions attribute name.

HOOK = 'hook'

hook attribute name.

MAX_TRIES = 'max_tries'

max_tries attribute name.

ON_ERROR = 1

on error retries condition.

ON_SUCCESS = 2

on success retries condition.

backoff
condition
delay
enable
exceptions
hook
interception
max_tries
override
propagate
targets
class b3j0f.annotation.call.Memoize(max_size=9223372036854775807, *args, **kwargs)[source]

Bases: b3j0f.annotation.interception.PrivateInterceptor

Save funtion results related to called parameters.

Parameters must be hashable.

DEFAULT_MAX_SIZE = 9223372036854775807

default max size value.

MAX_SIZE = 'max_size'

max size result.

clearcache()[source]

Clear cache.

enable
getparams(result)[source]

Get result parameters.

Parameters:result – cached result.
Raises:ValueError if result is not cached.
Returns:args and kwargs registered with input result.
Return type:tuple
interception
max_size
override
propagate
targets