corelay.plugboard
A module that contains the Plugboard class. Plugboards manage instances of Slot,
which describe values. A Slot can be filled using a Plug, which represents a concrete
value.
Classes
|
|
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 |
|
A proxy-object descriptor class to access the default values of the owning class of a |
- class corelay.plugboard.EmptyInit[source]
Bases:
objectEmptyInitis a class intended to be inherited as a last step down the MRO, to catch any remaining positional and/or keyword arguments and thus raise proper exceptions.- __init__() None[source]
Initializes a new instance of
EmptyInit.Note
This is not intended to be called directly, but rather by the constructor of the next class up in the inheritance hierarchy. The super-delegation is not unnecessary, even if PyLint claims so, since this is causes Python to raise a more informative exception when the user tries to pass more keyword arguments than are accepted by the constructors in the inheritance hierarchy. If the constructor of the penultimate class in inheritance hierarchy calls this constructor and there are still keyword arguments left, Python will raise a
TypeErrorwith a message like “TypeError: object.__init__() takes exactly one argument (the instance to initialize)”. This may confuse users, but if the constructor call is delegated to the next class up (i.e.,object), the exception will be more informative and say something like: “TypeError: Empty.__init__() takes 0 positional arguments but 1 was given”.- Return type:
None
- class corelay.plugboard.Slot[source]
Bases:
EmptyInitSlots are descriptors that contain objects in a container called
Plug. Instances of theSlotclass have adtypeand adefaultvalue, which are enforced to be consistent. When aSlotinstance is accessed in a class, it will return the contained object of itsPlugcontainer. When accessing or assigningSlotinstances in a class that have never been accessed before, aPlugobject is stored in the class’__dict__under the same name theSlotwas assigned to in the class. Slots may have theirdefaultvalue set toNone, in which case setting plugs belonging to it must have either aPlug.defaultvalue, or an explicitPlug.objvalue on their own. Calling aSlotinstance creates a correspondingPlugcontainer instance.Note
See https://docs.python.org/3/howto/descriptor.html for more information on descriptors.
- __init__(dtype: type | tuple[type, ...] = object, default: Any = None, **kwargs: Any) None[source]
Initializes a new
Slotinstance. Configures that data type and the default value of the slot. A consistency check is performed to ensure that the default value is of the correct type.- Parameters:
dtype (type | tuple[type, ...]) – The data type of the slot. This can be a single type or a tuple of types. The value of the plug, as well as the default value, must be of this type or one of the types in the tuple. Defaults to
object.default (Any) – The default value of the plug. The default value must be an instance of the specified data type
dtypeor one of the types in the tuple. If no default value is set, it will beNone. When a plug is created without an explicit value, it will use this default value. Defaults toNone.**kwargs (Any) – Additional keyword arguments that are passed to the parent class constructor. This is done for cooperativity’s sake, as the next class one step up in the inheritance hierarchy will be EmptyInit, which does not accept any additional keyword arguments and will raise an exception if any are passed.
- Return type:
None
- get_plug(instance: Any, obj: Any = None, default: Any = None) Plug[source]
Gets a corresponding
Plugthat can be used to access the__dict__of theSlotinstance . In case a newPlughas to be created, theobjanddefaultparameters may be specified.- Parameters:
- Returns:
Returns a
Plugcontainer. If aPluginstance already exists in the instance’s__dict__it is returned. Otherwise, a newPlugcontainer is created, which is also appended to the instance’s__dict__. If a newPluginstance is created, theobjanddefaultvalues are set to the values passed in.- Return type:
- __set_name__(owner: type, name: str) None[source]
Is invoked, when the
Slotis assigned to a class or instance attribute. Sets the name of the slot when assigned under a class. Necessary to write the correct__dict__entry in the parent class.
- __get__(instance: Any, owner: type) Slot | Any[source]
Is invoked, when the class or instance attribute the
Slotwas assigned to is read. When theSlotis accessed from a class, theSlotinstance itself is returned. If accessed using an instance, the correspondingPlugcontainer’s value is returned.
- __set__(instance: Any, value: Any) None[source]
Is invoked, when the class or instance attribute the
Slotwas assigned to is written. Sets the instance’sPlugcontainer object value.
- __delete__(instance: Any) None[source]
Is invoked, when the class or instance attribute the
Slotwas assigned to is deleted. Deletes the instance’sPlugcontainer object value if it exists, enforcing the use of its default value.
- class corelay.plugboard.Plug[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.- __init__(slot: Slot, obj: Any = None, default: Any = None, **kwargs: Any) None[source]
Initializes a new
Pluginstance and checks for consistency.- Parameters:
slot (Slot) – The
Slotinstance to associate with thisPlug.obj (Any) – An explicitly defined object held in the
Plugcontainer. If not set,defaultis returned as its value.default (Any) – A plug-dependent lower-priority object held in the
Plugcontainer. If not set,fallbackis returned.**kwargs (Any) – Keyword arguments passed down to the base class constructor, for cooperativity’s sake. In normal cases, this next class will be
EmptyInit, which accepts no more keyword arguments and will raise an exception.
- Return type:
None
- property dtype: type | tuple[type, ...]
Gets the
Slot.dtypeof the associatedSlot. Thedtypeproperty is non-mutable.- Returns:
Returns the
Slot.dtypeof the associatedSlot.- Return type:
- property optional: bool
Gets a value indicating whether the
Plugcontainer has a default value. ThePlug.optionalproperty is non-mutable.
- property fallback: Any
Gets the default value of the associated
Slot. Thefallbackproperty is non-mutable.
- class corelay.plugboard.SlotDefaultAccess[source]
Bases:
objectA proxy-object descriptor class to access the default values of the owning class of a
Slot, sinceSlotinstances cannot be returned except by accessing a classes’__dict__.- __init__(instance: Tracker | Any = None) None[source]
Initializes a new
SlotDefaultAccessinstance.- Parameters:
instance (Tracker | Any) – The instance of the class the
SlotDefaultAccessis associated with.- Return type:
None
- __get__(instance: Any, owner: Any) SlotDefaultAccess[source]
Is invoked when the property, the
SlotDefaultAccessis stored in, is retrieved. Returns a newSlotDefaultAccessinstance initialized with the provided instance value, which is the instance of the class that is the owner of theSlotDefaultAccess.- Parameters:
instance (Any) – The instance of the class the
SlotDefaultAccessis associated with.owner (Any) – The class of the
instancethat owns theSlotDefaultAccess.
- Returns:
Returns a new instance of
SlotDefaultAccessinitialized with the provided instance value.- Return type:
- class corelay.plugboard.Plugboard[source]
-
Optional Manager class for slots. Uses
SlotDefaultAccessto accessPlugdefault values. Also initializesPlugcontainer object values during instantiation by keywords.See also
- __tracked__: collections.OrderedDict[str, Any]
An
collections.OrderedDictwith all public class attributes, i.e., all class attributes not enclosed with double underscores.
- __init__(**kwargs: Any) None[source]
Initializes a new
Plugboardinstance and initializes the slots via the keyword arguments passed in.- Parameters:
**kwargs (Any) – The keyword arguments that are used to initialize slots. Only keyword arguments which correspond to the slot attribute names of the class are processed. All other keyword arguments are passed to the constructor of the next class in the inheritance hierarchy.
- Return type:
None