Add MarkedDict.keydict attribute

Useful for preserving marked keys
This commit is contained in:
ZyX 2014-08-25 00:37:25 +04:00
parent 3a608d838d
commit f8bea417fe
1 changed files with 12 additions and 1 deletions

View File

@ -64,9 +64,20 @@ class MarkedFloat(float):
class MarkedDict(dict):
__new__ = gen_new(dict)
__init__ = gen_init(dict)
__getnewargs__ = gen_getnewargs(dict)
def __init__(self, value, mark):
dict.__init__(self, value)
self.keydict = dict(((key, key) for key in self))
def __setitem__(self, key, value):
dict.__setitem__(self, key, value)
self.keydict[key] = key
def update(self, *args, **kwargs):
dict.update(self, *args, **kwargs)
self.keydict = dict(((key, key) for key in self))
def copy(self):
return MarkedDict(super(MarkedDict, self).copy(), self.mark)