laser.core.propertyset
laser.core.propertyset
Implements a PropertySet class that can be used to store properties in a dictionary-like object.
laser.core.propertyset.PropertySet(*bags)
A class that can be used to store properties in a dictionary-like object with .property access to properties.
Examples
Basic Initialization:
::
1 2 3 4 5 6 | |
Combining two PropertySets:
::
1 2 3 4 5 | |
Creating a PropertySet from a dictionary:
::
1 2 3 4 5 | |
Save and load:
::
1 2 3 | |
Property access and length:
::
1 2 3 4 | |
In-Place addition (added keys must not exist in the destination PropertySet):
::
1 2 3 | |
In-place update (keys must already exist in the destination PropertySet):
::
1 2 3 | |
In-place addition or update (no restriction on incoming keys):
::
1 2 3 | |
Initialize a PropertySet to manage properties in a dictionary-like structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bags
|
Union[PropertySet, list, tuple, dict]
|
A sequence of key-value pairs (e.g., lists, tuples, dictionaries) to initialize the PropertySet. Keys must be strings, and values can be any type. |
()
|
laser.core.propertyset.PropertySet.__add__(other)
Add another PropertySet to this PropertySet.
This method allows the use of the + operator to combine two PropertySet instances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
PropertySet
|
The other PropertySet instance to add. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
PropertySet |
PropertySet
|
A new PropertySet instance that combines the properties of both instances. |
laser.core.propertyset.PropertySet.__contains__(key)
Check if a key is in the property set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to check for existence in the property set. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the key exists in the property set, False otherwise. |
laser.core.propertyset.PropertySet.__eq__(other)
Check if two PropertySet instances are equal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
PropertySet
|
The other PropertySet instance to compare. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the two instances are equal, False otherwise. |
laser.core.propertyset.PropertySet.__getitem__(key)
Retrieve the attribute of the object with the given key (e.g., ps[key]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The name of the attribute to retrieve. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
any
|
The value of the attribute with the specified key. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the attribute with the specified key does not exist. |
laser.core.propertyset.PropertySet.__iadd__(other)
Implements the in-place addition (+=) operator for the class.
This method allows the instance to be updated with attributes from another
instance of the same class or from a dictionary. If other is an instance
of the same class, its attributes are copied to the current instance. If
other is a dictionary, its key-value pairs are added as attributes to
the current instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Union[type(self), dict]
|
The object or dictionary to add to the current instance. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
self |
PropertySet
|
The updated instance with the new attributes. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If |
ValueError
|
If |
laser.core.propertyset.PropertySet.__ilshift__(other)
Implements the <<= operator on PropertySet to override existing values with new values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Union[type(self), dict]
|
The object or dictionary with overriding values. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
self |
PropertySet
|
The updated instance with the overrides from other. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If |
ValueError
|
If |
laser.core.propertyset.PropertySet.__ior__(other)
Implements the |= operator on PropertySet to override existing values with new values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Union[type(self), dict]
|
The object or dictionary with overriding values. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
self |
PropertySet
|
The updated instance with all the values of self with new or overriding values from other. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If |
laser.core.propertyset.PropertySet.__len__()
Return the number of attributes in the instance.
This method returns the number of attributes stored in the instance's dict attribute, which represents the instance's namespace.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The number of attributes in the instance. |
laser.core.propertyset.PropertySet.__lshift__(other)
Implements the << operator on PropertySet to override existing values with new values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Union[type(self), dict]
|
The object or dictionary with overriding values. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
PropertySet |
PropertySet
|
A new PropertySet with all the values of the first PropertySet with overrides from the second PropertySet. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If |
ValueError
|
If |
laser.core.propertyset.PropertySet.__or__(other)
Implements the | operator on PropertySet to add new or override existing values with new values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Union[type(self), dict]
|
The object or dictionary with overriding values. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
PropertySet |
PropertySet
|
A new PropertySet with all the values of the first PropertySet with new or overriding values from the second PropertySet. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If |
laser.core.propertyset.PropertySet.__repr__()
Return a string representation of the PropertySet instance.
The string representation includes the class name and the dictionary of the instance's attributes.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A string representation of the PropertySet instance. |
laser.core.propertyset.PropertySet.__setitem__(key, value)
Set the value of an attribute.
This method allows setting an attribute of the instance using the
dictionary-like syntax (e.g., ps[key] = value).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The name of the attribute to set. |
required |
value
|
any
|
The value to set for the attribute. |
required |
laser.core.propertyset.PropertySet.__str__()
Returns a string representation of the object's dictionary.
This method is used to provide a human-readable string representation
of the object, which includes all the attributes stored in the object's
__dict__.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A string representation of the object's dictionary. |
laser.core.propertyset.PropertySet.load(filename)
staticmethod
Load a PropertySet from a specified file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The path to the file where the PropertySet is saved. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
PropertySet |
PropertySet
|
The PropertySet instance loaded from the file. |
laser.core.propertyset.PropertySet.save(filename)
Save the PropertySet to a specified file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The path to the file where the PropertySet will be saved. |
required |
laser.core.propertyset.PropertySet.to_dict()
Convert the PropertySet to a dictionary.