class documentation

class DuplicateSafeDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): (source)

View In Hierarchy

Dictionnary that do not discard old objects when they are overriden, but instead, only updates a reference to the new object.

Duplicate values can be fetched with methods getall, getdup and allitems.

>>> d = DuplicateSafeDict(me='bob', you='claudia')
>>> d['me'] = 'james'
>>> d['me'] = 'james'
>>> d['me'] = 'bob'
>>> d.getall('me')
['james', 'bob']
>>> d['me'] = 'james'
>>> d.getall('me')
['bob', 'james']
>>> d.getdup('me')
['bob']
>>> d == {'me':'bob', 'you':'claudia'}
False
>>> d == DuplicateSafeDict([('me', 'bob'), ('me', 'james'), ('you', 'claudia')])
True
>>> del d['me']
>>> d.getall('me')
['bob']
>>> d == dict([('me', 'bob'), ('you', 'claudia')])
True
Method __delitem__ Remove the last element added value for a key.
Method __eq__ Undocumented
Method __getitem__ Return the last element added that matches the name.
Method __init__ Undocumented
Method __iter__ Undocumented
Method __len__ Undocumented
Method __repr__ Undocumented
Method __setitem__ Undocumented
Method addvalue No summary
Method allitems Like 'items()' but returns all values, including duplicates.
Method copy Undocumented
Method getall Like 'get()' but returns all values for that name, including duplicates.
Method getdup Return the duplicates objects for that name. List might be empty. Raise key error if the name doesn't exist.
Method rmvalue Remove a value from the dict. The value can be a duplicate. If no values are left in the queue after the removal, the whole queue will be deleted.
Instance Variable _store Undocumented
def __delitem__(self, key): (source)

Remove the last element added value for a key.

Parameters
key:_KTUndocumented
def __eq__(self, other): (source)

Undocumented

Parameters
other:AnyUndocumented
Returns
boolUndocumented
def __getitem__(self, key): (source)

Return the last element added that matches the name.

Parameters
key:_KTUndocumented
Returns
_VTUndocumented
def __init__(self, data=None, **kwargs): (source)

Undocumented

Parameters
data:Optional[Union[Mapping[_KT, _VT], Iterable[Tuple[_KT, _VT]]]]Undocumented
**kwargs:AnyUndocumented
def __iter__(self): (source)

Undocumented

Returns
Iterator[_KT]Undocumented
def __len__(self): (source)

Undocumented

Returns
intUndocumented
def __repr__(self): (source)

Undocumented

Returns
strUndocumented
def __setitem__(self, key, value): (source)

Undocumented

Parameters
key:_KTUndocumented
value:_VTUndocumented
def addvalue(self, key, value, shadow=True): (source)
Parameters
key:_KTUndocumented
value:_VTUndocumented
shadow:boolShadow or not an already existent value for that key. Old value is still accessible with getall() and getdup().
def allitems(self): (source)

Like 'items()' but returns all values, including duplicates.

Returns
Iterator[Tuple[_KT, _VT]]Undocumented
def copy(self): (source)

Undocumented

Returns
DuplicateSafeDict[_KT, _VT]Undocumented
def getall(self, key, default=None): (source)

Like 'get()' but returns all values for that name, including duplicates.

Parameters
key:_KTUndocumented
default:Optional[List[_VT]]Undocumented
Returns
Optional[List[_VT]]Undocumented
def getdup(self, key): (source)

Return the duplicates objects for that name. List might be empty. Raise key error if the name doesn't exist.

Parameters
key:_KTUndocumented
Returns
List[_VT]Undocumented
def rmvalue(self, key, value): (source)

Remove a value from the dict. The value can be a duplicate. If no values are left in the queue after the removal, the whole queue will be deleted.

Raise key error if no values exists for the key. Raise value error if the value if not present.

Parameters
key:_KTUndocumented
value:_VTUndocumented
_store: Dict[_KT, List[_VT]] = (source)

Undocumented