any2any 0.1 documentation


«  any2any.base   ::   Contents   ::   any2any.daccasts  »


Metamorphoses (Mm)

class any2any.utils.Mm(from_=None, to=None, from_any=None, to_any=None)

A metamorphosis between two types. For example :

>>> mm1 = Mm(LoisClark, Superman)
>>> mm2 = Mm(from_any=Human, to_any=SuperHero)
>>> mm1 < mm2 # i.e. <mm1> is included in <mm2>
  • from_(type). Metamorphosis only from type from_ (and no subclass).
  • to(type). Metamorphosis only to type to (and no subclass).
  • from_any(type). Metamorphosis from type from_any and subclasses.
  • to_any(type). Metamorphosis from type to_any and subclasses.


class any2any.utils.WrappedObject

Subclass WrappedObject to create a placeholder containing extra-information on a type. e.g. :

>>> class WrappedInt(WrappedObject):
...     klass = int
...     greater_than = 0

A subclass of WrappedObject can also provide informations on the wrapped type’s instances’ :


type. The wrapped type.

alias of object

factory = None

type. The type used for instance creation :

>>> class WrappedBS(WrappedObject):
...     klass = basestring
...     factory = str
>>> a_str = WrappedBS("blabla")
>>> type(a_str) == str
superclasses = ()

tuple. Allows to customize WrappedObject.issubclass() behaviour :

>>> class WrappedStr(WrappedObject):
...     klass=str
...     superclasses=(MyStr, AllStrings)
>>> WrappedObject.issubclass(WrappedStr, str), WrappedObject.issubclass(WrappedStr, MyStr), # ...
(True, True)
extra_schema = {}

dict. {<attribute_name>: <attribute_type>}. Allows to update the default schema, see get_schema().

include = []

list. The list of attributes to include in the schema see, get_schema().

exclude = []

list. The list of attributes to exclude from the schema see, get_schema().

classmethod get_class(key)

Returns the class of attribute key, as found from the schema, see get_schema().

classmethod get_schema()

Returns the full schema {<attribute_name>: <attribute_type>} of an instance, taking into account (respectively) : default_schema, extra_schema, include and exclude.

classmethod default_schema()

Returns the schema - known a priori - of an instance. Must return a dictionary with the format {<attribute_name>: <attribute_type>}.

classmethod setattr(instance, name, value)

Sets the attribute name on instance, with value value. If the calling WrappedObject has a method set_<name>, this method will be used to set the attribute.

classmethod getattr(instance, name)

Gets the attribute name from instance. If the calling WrappedObject has a method get_<name>, this method will be used to get the attribute.

classmethod new(*args, **kwargs)

Creates and returns a new instance of the wrapped type.

«  any2any.base   ::   Contents   ::   any2any.daccasts  »