wmaee.core.data_structs

 1from typing import Any, Dict
 2
 3class DotDict(dict):
 4    """A custom dictionary class that allows accessing items using dot notation.
 5
 6    Example:
 7    >>> my_dict = DotDict({"item": "value"})
 8    >>> item_value = my_dict.item
 9    >>> print(item_value)
10    "value"
11    """
12
13    def __getattr__(self, attr: str) -> Any:
14        """Retrieve a dictionary item using dot notation.
15
16        Args:
17            attr (str): The key for the item to retrieve.
18
19        Returns:
20            Any: The value associated with the given key.
21
22        Raises:
23            AttributeError: If the key does not exist in the dictionary.
24
25        Example:
26        >>> my_dict = DotDict({"item": "value"})
27        >>> item_value = my_dict.item
28        """
29        if attr in self:
30            return self[attr]
31        raise AttributeError(f"'DotDict' object has no attribute '{attr}'")
class DotDict(builtins.dict):
 4class DotDict(dict):
 5    """A custom dictionary class that allows accessing items using dot notation.
 6
 7    Example:
 8    >>> my_dict = DotDict({"item": "value"})
 9    >>> item_value = my_dict.item
10    >>> print(item_value)
11    "value"
12    """
13
14    def __getattr__(self, attr: str) -> Any:
15        """Retrieve a dictionary item using dot notation.
16
17        Args:
18            attr (str): The key for the item to retrieve.
19
20        Returns:
21            Any: The value associated with the given key.
22
23        Raises:
24            AttributeError: If the key does not exist in the dictionary.
25
26        Example:
27        >>> my_dict = DotDict({"item": "value"})
28        >>> item_value = my_dict.item
29        """
30        if attr in self:
31            return self[attr]
32        raise AttributeError(f"'DotDict' object has no attribute '{attr}'")

A custom dictionary class that allows accessing items using dot notation.

Example:

>>> my_dict = DotDict({"item": "value"})
>>> item_value = my_dict.item
>>> print(item_value)
"value"