netlist_carpentry.utils.custom_dict
¶
Module for a custom dictionary class, with some extensions to the normal Python dict.
Classes:
CustomDict
¶
Bases: Dict[K, V]
Methods:
-
add–Adds an element to this dictionary if the key does not already exist.
-
remove–Removes an entry from this dictionary if the key exists.
add
¶
Adds an element to this dictionary if the key does not already exist.
Parameters:
-
(key¶K) –The key under which the element should be stored.
-
(element¶V) –The element to be added.
-
(locked¶bool, default:False) –Whether the target dictionary can be modified. Useful to prevent changes e.g. in modules marked as locked. Defaults to False.
Returns:
-
V(V) –The element that was successfully added.
Raises:
-
IdentifierConflictError–If an object with the same key already exists.
-
ObjectLockedError–If "locked" is set to
True, i.e. the dict cannot be modified currently.
remove
¶
Removes an entry from this dictionary if the key exists.
Parameters:
-
(key¶K) –The key of the entry to be removed.
-
(locked¶bool, default:False) –Whether the target dictionary can be modified. Useful to prevent changes e.g. in modules marked as locked. Defaults to False.
Raises:
-
ObjectNotFoundError–If no object with the given key exists.
-
ObjectLockedError–If "locked" is set to
True, i.e. the dict cannot be modified currently.