corelay.plugboard

Plugboards are classes which contain Slots that are filled using Plugs.

Classes

EmptyInit

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.

Plug

Container class to fill Slots associated with a certain instance.

Plugboard

Optional Manager class for Slots.

Slot

Slots are descriptors that contain objects in a container called Plug.

SlotDefaultAccess

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: object

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.

class corelay.plugboard.Plug(slot, obj=None, default=None, **kwargs)[source]

Bases: EmptyInit

Container 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

slot

Slot with which this Plug is associated.

Type

Slot

dtype

dtype of the associated Slot.

Type

type

optional

Whether default or fallback is not None.

Type

bool

See also

Slot, Plugboard

class corelay.plugboard.Plugboard(**kwargs)[source]

Bases: Tracker, EmptyInit

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.

See also

Slot, SlotDefaultAcces, Plug

reset_defaults()[source]

Delete default values of all Plugs of this instance.

update_defaults(**kwargs)[source]

Update default values of Plugs of this instance by providing their name and a new value as keyword arguments.

class corelay.plugboard.Slot(dtype=<class 'object'>, default=None, **kwargs)[source]

Bases: EmptyInit

Slots 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

default

Default parameter value, should be an instance of (one of) dtype.

Type

dtype

optional

Non-mutuable. True, if Slot has a non-None default value, e.g. is optional.

Type

bool

See also

Plugboard, Plug

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
  • instance (object) – An instance of the class Slot was assigned in.

  • obj (dtype) – Object value to write to newly created Plug instances.

  • default (dtype) – Default value to write to newly created Plug instances.

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

Plug

class corelay.plugboard.SlotDefaultAccess(instance=None)[source]

Bases: object

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__.

See also

Slot, Plugboard, Plug