alias_dict

A Module containing a custom dictionary class that works with alias keys.

AliasDict

AliasDict()

Bases: dict[Any, Any]

flowchart LR tm_devices.helpers.alias_dict.AliasDict[AliasDict] click tm_devices.helpers.alias_dict.AliasDict href "" "tm_devices.helpers.alias_dict.AliasDict"

A custom dictionary class that supports aliases as secondary keys.

Each alias and key that is added must be unique, no duplicate aliases or keys are allowed.

Examples:

>>> from tm_devices.helpers.alias_dict import AliasDict
>>> new_dict = AliasDict()
>>> test_string = "value"
>>> new_dict["key"] = test_string
>>> new_dict["alias"] = test_string
>>> print(new_dict["key"])
value
>>> print(new_dict["alias"])
value
>>> assert id(new_dict["key"]) == id(new_dict["alias"])
>>> print(new_dict)
{'key': 'value'}
>>> print(len(new_dict))
1
>>> for key, value in new_dict.items():
...     print(f"{key=}, {value=}")
key='key', value='value'
>>> print(new_dict["key_2"])
Traceback (most recent call last):
    ...
KeyError: 'key_2'