Typing
Public typing helpers from annnet.utils.typing.
annnet.utils.typing
Classes
Attr
Enum class representing predefined attribute names used in the Attributes class.
Attributes:
| Name | Type | Description |
|---|---|---|
VALUE |
Represents the key for a value attribute.
|
EDGE_TYPE: Represents the key for an edge type attribute. SOURCE_ATTR: Represents the key for a source attribute. TARGET_ATTR: Represents the key for a target attribute. CUSTOM_ATTR: Represents the key for a custom attribute. |
Attributes
A dictionary-based class to manage attributes.
Uses reserved attributes used by CORNETO Graphs.
Functions
Set an attribute as a dictionary key-value pair.
Raises an error if the attribute name is a protected dictionary attribute.
Args:
__name (str): The name of the attribute to set.
__value (Any): The value to assign to the attribute. If the value is an instance
of Attr, its value is used.
Raises:
| Type | Description |
|---|---|
AttributeError: If trying to set a protected attribute.
|
|
Retrieve the value of an attribute if it exists in the dictionary.
Args: __name (str): The name of the attribute to retrieve.
Returns:
| Type | Description |
|---|---|
Any: The value of the requested attribute.
|
|
Raises:
| Type | Description |
|---|---|
AttributeError: If the attribute does not exist.
|
|
Set an attribute in the dictionary using an Attr key.
Args:
key (Attr): The key for the attribute, represented as an Attr enum.
value (Any): The value to assign to the key. If the value is an enum,
its value is used.
Check if a given attribute exists in the dictionary, optionally with a specific value.
Args:
key (Attr): The key for the attribute, represented as an Attr enum.
value (Optional[Any]): The optional value to check for.
Returns:
| Type | Description |
|---|---|
bool: `True` if the attribute exists and matches the value (if provided),
|
otherwise |
Retrieve the value of an attribute, or return a default value if not found.
Args:
key (Attr): The key for the attribute, represented as an Attr enum.
default (Any): The default value to return if the attribute does not exist.
Returns:
| Type | Description |
|---|---|
Any: The value of the attribute, or the default value if not found.
|
|