corelay.plugboard
Plugboards are classes which contain Slots that are filled using Plugs.
Classes
Empty Init is a class intened to be inherited as a last step down the MRO, to catch any remaining positional and/or keyword arguments and thus raise proper Exceptions. |
|
Container class to fill Slots associated with a certain instance. |
|
Optional Manager class for Slots. |
|
Slots are descriptors that contain objects in a container called Plug. |
|
A proxy-object descriptor class to access Plug default values of the owning class, since Plug-instances can not be returned except by accessing a classes' __dict__. |
- class corelay.plugboard.EmptyInit[source]
Bases:
objectEmpty Init is a class intened to be inherited as a last step down the MRO, to catch any remaining positional and/or keyword arguments and thus raise proper Exceptions.
- class corelay.plugboard.Plug(slot, obj=None, default=None, **kwargs)[source]
Bases:
EmptyInitContainer class to fill Slots associated with a certain instance. The instance is usually of type Plugboard, but may be of any kind of type.
- obj
Explicitly defined object held in the Plug container. If not set, self.default is returned.
- Type:
object
- default
Plug-dependent lower-priority object held in the container. If not set, self.fallback is returned.
- Type:
object
- fallback
Slot-dependent lowest-priority value to fall back to when no value has been assigned to the container. If not set, a TypeError is returned.
- Type:
object
- dtype
dtype of the associated Slot.
- Type:
type
- optional
Whether default or fallback is not None.
- Type:
bool
- class corelay.plugboard.Plugboard(**kwargs)[source]
-
Optional Manager class for Slots. Uses SlotDefaultAccess to access Plug default values. Also intializes Plug container object values during instatiation by keywords.
- Parameters:
default (
SlotDefaultAccess) – Proxy object to access instance’s Plug’s default values by attribute.
- class corelay.plugboard.Slot(dtype=<class 'object'>, default=None, **kwargs)[source]
Bases:
EmptyInitSlots are descriptors that contain objects in a container called Plug. Slot`s have a dtype and a default value, which are enforced to be consistent. When a Slot instance is accessed in a class, it will return the contained object of its `Plug container. When accessing or assigning Slot instances in a class, if it never has been accessed before, a Plug object is stored in the class’ __dict__ under the same name the Slot was assigned to in the class. Slots may have their default value set to None, in which case setting Plugs belonging to it must have either a default, or an explicit object value on their own. Calling a Slot instance creates a corresponding Plug container instance.
Note
See https://docs.python.org/3/howto/descriptor.html for information on descriptors.
- dtype
Allowed type(s) of the parameter.
- Type:
type or tuple of type
- optional
Non-mutuable. True, if Slot has a non-None default value, e.g. is optional.
- Type:
bool
- get_plug(instance, obj=None, default=None)[source]
Get a corresponding Plug be accessing the Slot’s instance’s __dict__. For accessing a newly created and possibly mandatory Plug’s, a obj and default value may be passed.
- Parameters:
- Returns:
Either an existing Plug container from the instance’s __dict__ if available, or a newly created Plug container instance, which is also appended to the instance’s __dict__.
- Return type: