Creator¶
creator
¶
create_type(name, base, **kwargs)
¶
Create a class named name and register it on the creator module.
The new class inherits from base. Each keyword argument becomes
an attribute: a class object is stored as an instance attribute
(instantiated when each individual is created); any other value is
stored as a class attribute.
Calling it again with the same name and an equal definition returns the existing class unchanged, so live instances and pickles keep working. A different definition under an existing name warns and replaces the old class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the class to create. |
required |
base
|
type | object
|
Type or instance to inherit from. An instance is replaced by its class. |
required |
**kwargs
|
Any
|
Attributes added to the new class. |
{}
|
Returns:
| Type | Description |
|---|---|
type
|
The created class, or the existing one for an equal definition. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |