b3j0f.annotation package

Module contents

class b3j0f.annotation.Annotation(on_bind_target=None, propagate=True, override=False, ttl=None, in_memory=False)

Bases: object

Base class for all annotations defined in this library.

It contains functions to override in order to catch initialisation of this Annotation and annotated elements binding (also called commonly target in the context of Annotation).

All annotations which inherit from this are registered to target objects and are accessibles through the static method Annotation.get_annotations.

Instance methods to override are: - __init__: set parameters during its instantiation. - _bind_target: called to bind target to this. - on_bind_target: fired when the annotated element is bound to this.

And properties are: - propagate: (default True) determines if an annotation is propagated to all sub target elements. - override: (default False) exclude previous annotation of the same type as self class. - _ttl: (default None) self time to leave. - _in_memory: (default False) save instance in a global dictionary.

It is also possible to set on_bind_target, propagate and override in
the constructor.
IN_MEMORY = '_in_memory'
OVERRIDE = 'override'
PROPAGATE = 'propagate'
TARGETS = 'targets'
TTL = '_ttl'
bind_target(target, ctx=None)

Bind self annotation to target.

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

bound target.

classmethod free_memory(annotation_type, exclude=None)

Free global annotation memory.

classmethod get_annotated_fields(annotation_type, instance, select=<function <lambda> at 0x2488398>)

Get dict of {annotated fields: annotations} by annotation_type of input instance.

Returns:a set of (annotated fields, annotations)
Return type:dict
classmethod get_annotations(annotation_type, target, exclude=None, ctx=None, select=<function <lambda> at 0x24882a8>)

Returns all input target annotations of annotation_type type sorted by definition order.

Parameters:
  • annotation_type (type) – type of annotation to get from target.
  • target – target from where get annotations.
  • exclude (tuple/type) – annotation types to remove from selection.
  • ctx – target ctx.
  • select – bool function which select annotations after applying previous type filters. Takes a target, a ctx and an annotation in parameters. True by default.
classmethod get_local_annotations(annotation_type, target, exclude=None, ctx=None, select=<function <lambda> at 0x24880c8>)
Get a list of local target annotations in the order of their
definition.
Parameters:
  • annotation_type (type) – type of annotation to get from target.
  • target – target from where get annotations.
  • exclude (tuple/type) – annotation types to exclude from selection.
  • ctx – target ctx.
  • select – selection function which takes in parameters a target, a ctx and an annotation and returns True if the annotation has to be selected. True by default.
Returns:

target local annotations

Return type:

list

classmethod get_memory_annotations(annotation_type, exclude=None)

Get annotations in memory which inherits from annotation_type.

Parameters:exclude (tuple/type) – annotation type(s) to exclude from search
Returns:found annotations which inherits from annotation_type.
Return type:set
in_memory
Returns:True if self is in a global memory of annotations.
on_bind_target(target, ctx=None)

Fired after target is bound to self.

Parameters:
  • target – newly bound target.
  • ctx – target ctx.
override
propagate
classmethod remove(annotation_type, target, exclude=None, ctx=None, select=<function <lambda> at 0x24881b8>)

Remove from target annotations which inherit from annotation_type

Parameters:
  • target – target from where remove annotations which inherits from annotation_type.
  • exclude (tuple/type) – annotation types to exclude from selection.
  • ctx – target ctx.
  • select – annotation selection function which takes in parameters a target, a ctx and an annotation and return True if the annotation has to be removed.
remove_from(target, ctx=None)

Remove self annotation from target annotations.

Parameters:
  • target – target from where remove self annotation.
  • ctx – target ctx.
targets
ttl

Get actual ttl in seconds.

Returns:actual ttl
Return type:float
class b3j0f.annotation.StopPropagation(*annotation_types, **kwargs)

Bases: b3j0f.annotation.core.Annotation

Stop propagation for annotation types.

ANNOTATION_TYPES = 'annotation_types'
annotation_types
override
propagate
targets
class b3j0f.annotation.RoutineAnnotation(routine=None, params=None, result=None, *args, **kwargs)

Bases: b3j0f.annotation.core.Annotation

Dedicated to add information on any routine, routine parameters or routine result.

PARAMS = 'params'
RESULT = 'result'
ROUTINE = 'routine'
override
params
propagate
result
routine
targets

Table Of Contents

Previous topic

b3j0f package

Next topic

b3j0f.annotation.test package

This Page