Skip to content

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: 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
__setattr__(__name, __value)

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: AttributeError: If trying to set a protected attribute.

__getattr__(__name)

Retrieve the value of an attribute if it exists in the dictionary.

Args: __name (str): The name of the attribute to retrieve.

Returns: Any: The value of the requested attribute.

Raises: AttributeError: If the attribute does not exist.

set_attr(key, value)

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.

has_attr(key, value=None)

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: bool: True if the attribute exists and matches the value (if provided), otherwise False.

get_attr(key, default=None)

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: Any: The value of the attribute, or the default value if not found.