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 NotEmpty(_type)[source]

Bases: b3j0f.annotation.call._SpecialCondition

class Types.NotNone(_type)[source]

Bases: b3j0f.annotation.call._SpecialCondition

Types.PTYPES = 'ptypes'

parameter types attribute name

Types.RTYPE = 'rtype'

return type attribute name

exception Types.TypesError[source]

Bases: exceptions.Exception

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

args may contain rtype and kwargs is ptypes.

class b3j0f.annotation.call.Curried(varargs=(), keywords={}, *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, *args, **kwargs)[source]

Bases: b3j0f.annotation.interception.PrivateInterceptor

Function decorator implementing retrying logic.

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(tries_remaining, exception); default None.

The decorator will call the function up to max_tries times if it raises an exception.

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.

BACKOFF = 'backoff'
DELAY = 'delay'
EXCEPTIONS = 'exceptions'
HOOK = 'hook'
MAX_TRIES = 'max_tries'
backoff
delay
enable
exceptions
hook
interception
max_tries
override
propagate
targets

Previous topic

b3j0f.annotation.async module

Next topic

b3j0f.annotation.check module

This Page