Skip to content

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

add(key: K, element: V, locked: bool = False) -> V

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:

remove

remove(key: K, locked: bool = False) -> None

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: