In [1]:
import modeled
print(modeled.__version__)
In [2]:
print(modeled.__description__)
In [9]:
modeled.__requires__
Out[9]:
All Python classes are derived from object
.
Modeled classes are derived from modeled.object
,
which has a predefined mobject
shortcut:
In [10]:
from modeled import mobject
In [11]:
class MClass(mobject):
# optional
class model:
name = 'NotMClass'
group__option = 'value'
class group:
other_option = 'other value'
Modeled members are the typed attributes of modeled objects.
They are defined as modeled class attributes
and connect to class instances via Python's descriptor mechanism.
These member descriptors are instances of the modeled.member
base class,
which has a predefined m
shortcut.
Typed member subclasses are created by passing any type (class object)
in [...]
brackets to the member base class:
In [4]:
from modeled import mobject, m
In [5]:
class MClass(mobject):
some_int = m[int]
some_float = m[float]
some_string = m[str]
These typed member suclasses are created only once for each given type.
Modeled member descriptors are automatically instantiated
by modeled.object
's metaclass.
You can easily access these instances on modeled class level:
In [6]:
MClass.some_int
Out[6]:
In [7]:
MClass.some_int.mtype
Out[7]:
Manually instantiate a member descriptor for defining a default value or passing extra keyword arguments or options:
In [9]:
class MClass(mobject):
some_int = m[int](4, name='not_some_int', group__option='value')
Other keyword arguments are:
new=
Any callable object which will be called instead of member's data type
if setting a member value which is not an instance of data type.
Must return a data type instance.choices=
A sequence of allowed member values.changed=
A sequence of callback functions (any callable objects)
to be triggered after setting member values.
Get the modeled class instance as first and the value as second argument.When providing a default value, the data type can be omitted:
In [10]:
m(4)
Out[10]: