owmeta_core.contextualize module¶
- class owmeta_core.contextualize.AbstractBaseContextualizable[source]¶
Bases:
ABC
Abstract base class for contextualizables
Any class with an attribute
contextualize
with a Function value is recognized as a subclass
- class owmeta_core.contextualize.BaseContextualizable(*args, **kwargs)[source]¶
Bases:
object
Helper base-class for contextualizable objects. Caches contextualized objects returned from
contextualize_augment
- add_contextualization(context, contextualization)[source]¶
Manually add a contextualized object to the cache
- Parameters
- context
Context
The context of the object
- contextualization
object
The contextualized version of the object
- context
- contextualize(context)[source]¶
Return an object with the given context. If the provided
context
isNone
, thenself
MUST be returned unmodified. Prefer to overridecontextualize_agument
which will be called from this method.It is generally not correct to set a field on the object and return the same object as this would change the context for other users of the object. Also, returning a copy of the object is usually inappropriate for mutable objects. Immutable objects may maintain a ‘context’ property and return a copy of themselves with that property set to the provided
context
argument.
- class owmeta_core.contextualize.Contextualizable(*args, **kwargs)[source]¶
Bases:
BaseContextualizable
A
BaseContextualizable
with the addition of a default behavior of setting the context from the class’s ‘context’ attribute. This generally requires that for the metaclass of the Contextualizable that a ‘context’ data property is defined. For example:>>> class AMeta(ContextualizableClass): ... @property ... def context(self): ... return self.__context ... ... @context.setter ... def context(self, ctx): ... self.__context = ctx >>> class A(six.with_metaclass(Contextualizable)): ... pass
- class owmeta_core.contextualize.ContextualizableClass(name, typ, dct)[source]¶
Bases:
type
A super-type for contextualizable classes
- Attributes
- context_carries
tuple
of
str
When defining a specialized contextualizable class, you may want to define some attribute on the class that is only set if it’s declared directly in the class body (e.g., by using
property
and name mangling). However, by default, contextualization creates a subclass and you may want your property to be “carried” into the new context. You can achieve this by declaringcontext_carries
with the names of attributes that should be carried through a contextualization.
- context_carries