The dip.model module implements a declarative type system for Python.
Base class: Model
The Adapter class is the base class for all adapters.
Determine if this adapter can adapt a particular object. It is only called after it is known that the adapter can handle the object’s type.
Parameter: | adaptee – is the object to be adapted. |
---|---|
Returns: | True if the object can be adapted. This default implementation always returns True. |
Base class: ValueTypeFactory
The Any class encapsulates any Python object.
Initialise the object.
Parameters: |
|
---|
Validate an object according to the constraints. An exception is raised if the object is invalid.
Parameter: | value – the object to validate. |
---|---|
Returns: | the validated object. |
Base class: Model
The AttributeChange class contains the information that describes an observable change to a typed attribute. An instance is passed to the observer defined using observe().
Base class: ValueTypeFactory
The Bool class encapsulates a Python bool.
Initialise the object.
Parameters: |
|
---|
Validate a bool according to the constraints. An exception is raised if the bool is invalid.
Parameter: | value – the bool to validate. |
---|---|
Returns: | the validated bool. |
Base class: ValueTypeFactory
The Callable class encapsulates any callable object.
Initialise the object.
Parameters: |
|
---|
Validate an object according to the constraints. An exception is raised if the object is invalid.
Parameter: | value – the object to validate. |
---|---|
Returns: | the validated object. |
Base class: QObject
The ChangeTrigger class communicates a change on behalf of a particular instance of an attribute.
Base class: ValueTypeFactory
The CollectionTypeFactory class is a base class for all types that encapsulate objects of a particular type.
Resolve a type specification which is either None, a Python type (i.e. an instance of type), an instance of ValueTypeFactory or a string that is the “full” name of a Python type. The string form allows types to be specified while avoiding circular imports.
Parameters: |
|
---|---|
Returns: | the resolved type. |
Validate a type (either an instance of the builtin type or an instance of an attribute type factory) against a type associated with a collection. An exception is raised if the types are not compatible.
Parameters: |
|
---|
Validate a value contained in a collection. An exception is raised if the value is invalid.
Parameters: |
|
---|---|
Returns: | the validated value. |
Base class: ValueTypeFactory
The DelegatedTo class implements a delegate for another typed attribute.
Initialise the object.
Parameters: |
|
---|
Create a copy of this instance.
Returns: | the copied instance. |
---|
Get the containing model and name of the attribute that the delegate is acting for.
Parameter: | instance – is the DelegatedTo instance. |
---|---|
Returns: | a tuple of the containing model and the name of the attribute. |
Validate a value. This is only called to validate the default value which is a dummy.
Parameter: | value – the value to validate. |
---|---|
Returns: | the validated value. |
Base class: MutableTypeFactory
The Dict class encapsulates a Python dictionary with keys and values of particular types.
Initialise the object.
Parameters: |
|
---|
Create a copy of this instance.
Returns: | the copied instance. |
---|
Reimplemented to return a copy of the default because dictionaries are mutable.
Returns: | a copy of the default value. |
---|
Validate a dictionary according to the constraints. An exception is raised if the dictionary is invalid.
Parameter: | value – the dictionary to validate. |
---|---|
Returns: | the validated dictionary. |
Return a dictionary containing validated keys and values.
Parameter: | value – the dictionary of (possibly) invalid keys and values. |
---|---|
Returns: | a corresponding dictionary of validated keys and values. |
Base class: ValueTypeFactory
The Enum class encapsulates a fixed set of string values.
Initialise the object.
Parameters: |
|
---|
Create a copy of this instance.
Returns: | the copied instance. |
---|
Validate an object according to the constraints. An exception is raised if the object is invalid.
Parameter: | value – the object to validate. |
---|---|
Returns: | the validated object. |
Base class: ValueTypeFactory
The Float class encapsulates a Python float.
Initialise the object.
Parameters: |
|
---|
Validate a float according to the constraints. An exception is raised if the float is invalid.
Parameter: | value – the float to validate. |
---|---|
Returns: | the validated float. |
Base class: CollectionTypeFactory
The Instance class encapsulates an instance of a number of types.
Initialise the object.
Parameters: |
|
---|
Create a copy of this instance.
Returns: | the copied instance. |
---|
Reimplemented to compare two instances to see if they are different.
Parameters: |
|
---|---|
Returns: | True if the values are different. |
Validate an instance according to the constraints. An exception is raised if the instance is invalid.
Parameter: | value – the instance to validate. |
---|---|
Returns: | the validated instance. |
Base class: ValueTypeFactory
The Int class encapsulates a Python integer.
Initialise the object.
Parameters: |
|
---|
Validate an integer according to the constraints. An exception is raised if the integer is invalid.
Parameter: | value – the integer to validate. |
---|---|
Returns: | the validated integer. |
Base class: MutableTypeFactory
The List class encapsulates a Python list with elements of a particular type.
Initialise the object.
Parameters: |
|
---|
Create a copy of this instance.
Returns: | the copied instance. |
---|
Reimplemented to return a copy of the default because lists are mutable.
Returns: | a copy of the default value. |
---|
Validate a list according to the constraints. An exception is raised if the list is invalid.
Parameter: | value – the list to validate. |
---|---|
Returns: | the validated list. |
Return a list containing validated elements.
Parameter: | value – the list of (possibly) invalid elements. |
---|---|
Returns: | a corresponding list of validated elements. |
The MappingProxy class implements a Model based proxy for a mapping type. It is assumed that the mapping has string keys. Note that changes made to the object being proxied cannot be observed.
Base class: MetaModel
The MetaInterface class is the meta-class for Interface and is responsible for making an interface appear to be a super-class and invoking adapters when necessary.
This is called to create an instance of an object that implements an interface, either directly or by adaptation.
Parameters: |
|
---|---|
Returns: | an object, possibly an adapter, that implements the interface. |
Base class: pyqtWrapperType
The MetaModel class is the meta-class for Model and is responsible for initialising the attributes of an instance.
Base class: MetaModel
The MetaSingleton class is the meta-class for Singleton and is responsible for enforcing the singleton behaviour and implementing a read-only proxy for the managed instance.
Base class: CollectionTypeFactory
The MutableTypeFactory class is a base class for all mutable types.
This is called when a model attribute is being bound or rebound.
Parameters: |
|
---|
Base class: MutableTypeFactory
The Set class encapsulates a Python set with elements of a particular type.
Initialise the object.
Parameters: |
|
---|
Create a copy of this instance.
Returns: | the copied instance. |
---|
Reimplemented to return a copy of the default because sets are mutable.
Returns: | a copy of the default value. |
---|
Validate a set according to the constraints. An exception is raised if the set is invalid.
Parameter: | value – the set to validate. |
---|---|
Returns: | the validated set. |
Return a set containing validated elements.
Parameter: | value – the set of (possibly) invalid elements. |
---|---|
Returns: | a corresponding set of validated elements. |
The Singleton class is a base class for those classes implemented as a singleton and that manage an instance.
Base class: ValueTypeFactory
The Str class encapsulates a Python string.
Initialise the object.
Parameters: |
|
---|
Validate a string according to the constraints. An exception is raised if the string is invalid.
Parameter: | value – the string to validate. |
---|---|
Returns: | the validated string. |
Base class: CollectionTypeFactory
The Subclass class encapsulates any type object.
Initialise the object.
Parameters: |
|
---|
Create a copy of this instance.
Returns: | the copied instance. |
---|
Reimplemented to compare two sub-classes to see if they are different.
Parameters: |
|
---|---|
Returns: | True if the values are different. |
Validate an object according to the constraints. An exception is raised if the object is invalid.
Parameter: | value – the object to validate. |
---|---|
Returns: | the validated object. |
Base class: TypeFactory
The Trigger class represents an asynchronous event. Attributes of this type can be observed and can be set to any value (which is then discarded).
Initialise the object.
Parameter: | **metadata – is additional meta-data stored with the type. |
---|
Base class: CollectionTypeFactory
The Tuple class encapsulates a Python tuple with elements of a particular type.
Initialise the object.
Parameters: |
|
---|
Create a copy of this instance.
Returns: | the copied instance. |
---|
Validate a tuple according to the constraints. An exception is raised if the tuple is invalid.
Parameter: | value – the tuple to validate. |
---|---|
Returns: | the validated tuple. |
The TypeFactory class is the base class for all classes that create attribute types.
Initialise the object.
Parameter: | metadata – is a dictionary of additional meta-data stored with the type. |
---|
Create a clone of this instance.
Returns: | the cloned instance. |
---|
Base exception: TypeError
The ValidationError exception is raised when a value is invalid.
Base exception: ValidationError
The ValidationTypeError exception is raised when a value has an invalid type.
Base class: TypeFactory
The ValueTypeFactory class is the base class for all classes that create attribute types that have an associated stored value.
Initialise the object.
Parameters: |
|
---|
This is called when a model attribute is being bound or rebound.
Parameters: |
|
---|
Create a clone of this instance.
Returns: | the cloned instance. |
---|
Create a copy of this instance. This implementation is suitable for types that don’t have any additional data.
Returns: | the copied instance. |
---|
Compare two valid values to see if they are different.
Parameters: |
|
---|---|
Returns: | True if the values are different. |
Get the type’s default value. This implementation is appropriate for immutable types. Mutable types should reimplement it and return a copy of the default.
Returns: | the default value. |
---|
Set the type’s default value.
Parameter: | default – is the new default value. |
---|
Validate a value according to the type’s constraints. An exception is raised if the value is invalid.
This must be reimplemented by a sub-class.
Parameter: | value – the value to validate. |
---|---|
Returns: | the validated value (which may be normalised in some way). |
A class decorator that marks one or more classes, which must be sub-classes of Adapter, as being able to adapt an object to one or more interfaces. An instance of the adapter will be automatically created when required. Like the implements() class decorator any attributes of the interfaces that are not already present in the adapter are automatically added.
Parameters: |
|
---|
Get the TypeFactory sub-class instance for an attribute of a model.
Parameters: |
|
---|---|
Returns: | the attribute’s type object. |
Get the TypeFactory sub-class instances for all attributes of a model.
Parameters: |
|
---|---|
Returns: | the list of attribute types. |
Get the change trigger for an attribute of a model.
Parameters: |
|
---|---|
Returns: | the ChangeTrigger instance or None if the attribute is not being observed. |
Get a copy of the dictionary of TypeFactory sub-class instances, keyed by attribute name, for a model type.
Parameter: | model_type – is the Model sub-class. |
---|---|
Returns: | the dictionary of type objects. |
A class decorator that marks the class as implementing one or more interfaces. If a class implements an interface then issubclass() will return True when tested against the interface, isinstance() will return True when an instance of the class is tested against the interface. The decorator will automatically add any attributes of an interface that are not already present in the class.
Parameter: | *interfaces – are the interfaces that the class implements. |
---|
See if an object has been adapted to an interface.
Parameters: |
|
---|---|
Returns: | True if the object has been adapted to the interface. |
Notify any observers about a change to the value of an attribute of a model.
Parameters: |
|
---|
An attribute of a model is observed and an observer called when its value changes. This can also be used as a method decorator that uses the decorated method as the observer.
Parameters: |
|
---|
Return the sub-model and name referenced by an attribute path.
Parameters: |
|
---|---|
Returns: | the attribute name (which will not be an attribute path) and the sub-model. |