b3j0f.annotation.oop module

Annotations dedicated to object oriented programming.

class b3j0f.annotation.oop.Transform(name=None, bases=None, _dict=None, update=True, *args, **kwargs)[source]

Bases: b3j0f.annotation.core.Annotation

Transform a class into an annotation or something else if parameters are different.

BASES = 'bases'
DICT = 'dict'
NAME = 'name'
UPDATE = 'update'
bases
dict
name
override
propagate
targets
update
class b3j0f.annotation.oop.Mixin(classes=(), *attributes, **named_attributes)[source]

Bases: b3j0f.annotation.core.Annotation

Annotation which enrichs a target with Mixin.

For every defined mixin, a private couple of (name, array of mixed items) is created into the target in order to go back in a no mixin state.

exception MixInError[source]

Bases: exceptions.Exception

Raised for any Mixin error.

static Mixin.get_mixedins_by_name(target)[source]

Get a set of couple (name, field) of target mixedin.

static Mixin.mixin(target, resource, name=None)[source]

Do the correct mixin depending on the type of input resource.

  • Method or Function: mixin_function_or_method.
  • class: mixin_class.
  • other: set_mixin.

And returns the result of the choosen method (one or a list of mixins).

static Mixin.mixin_class(target, cls)[source]

Mix cls content in target.

static Mixin.mixin_function_or_method(target, routine, name=None, isbound=False)[source]

Mixin a routine into the target.

Parameters:
  • routine – routine to mix in target.
  • name (str) – mixin name. Routine name by default.
  • isbound (bool) – If True (False by default), the mixin result is a bound method to target.
Mixin.on_bind_target(target, ctx=None)[source]
static Mixin.remove_mixin(target, name, mixedin=None, replace=True)[source]

Remove a mixin with name (and reference) from targetand returns the replaced one or None.

Parameters:
  • mixedin – a mixedin value or the last defined mixedin if is None (by default).
  • replace (bool) – If True (default), the removed mixedin replaces the current mixin.
static Mixin.remove_mixins(target)[source]

Tries to get back target in a no mixin consistent state.

static Mixin.set_mixin(target, resource, name=None, override=True)[source]

Set a resource and returns the mixed one in target content or Mixin.__NEW_CONTENT_KEY__ if resource name didn’t exist in target.

Parameters:
  • name (str) – target content item to mix with the resource.
  • override (bool) – If True (default) permits to replace an old resource by the new one.
class b3j0f.annotation.oop.Deprecated(*args, **kwargs)[source]

Bases: b3j0f.annotation.interception.PrivateInterceptor

Decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used.

class b3j0f.annotation.oop.Singleton(*args, **kwargs)[source]

Bases: b3j0f.annotation.core.Annotation

Transforms cls into a singleton.

Reference to cls, or to any instance is the same reference.

class b3j0f.annotation.oop.MethodMixin(function, *args, **kwargs)[source]

Bases: b3j0f.annotation.core.Annotation

Apply a mixin on a method.