DisjointMappingGroup#

module wntr.utils.disjoint_mapping

class DisjointMappingGroup[source]#

Bases: MutableMapping

A dictionary that checks a namespace for existing entries.

To create a new instance, pass a set to act as a namespace. If the namespace does not exist, a new namespace will be instantiated. If it does exist, then a new, disjoint dictionary will be created that checks the namespace keys before it will allow a new item to be added to the dictionary. An item can only belong to one of the disjoint dictionaries associated with the namespace.

Examples

Assume there is a namespace nodes that has two distinct subsets of objects, tanks and reservoirs. A name for a tank cannot also be used for a reservoir, and a node cannot be both a tank and a reservoir. A DisjointNamespaceDict allows two separate dictionaries to be kept, one for each subtype, but the keys within the two dictionaries will be ensured to not overlap.

Parameters:
  • __keyspace (set) – the name of the namespace for consistency checking

  • args (Any) – regular arguments and keyword arguments passed to the underlying dictionary

  • kwargs (Any) – regular arguments and keyword arguments passed to the underlying dictionary


__init__(name, _keyspace)[source]#
static __new__(cls, name, _keyspace)[source]#
clear() None.  Remove all items from D.[source]#
get(k[, d]) D[k] if k in D, else d.  d defaults to None.#
items() a set-like object providing a view on D's items[source]#
keys() a set-like object providing a view on D's keys[source]#
pop(k[, d]) v, remove specified key and return the corresponding value.#

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() (k, v), remove and return some (key, value) pair[source]#

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D#
update([E, ]**F) None.  Update D from mapping/iterable E and F.#

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values() an object providing a view on D's values[source]#