Add MarkedList type
This commit is contained in:
parent
f482eea8be
commit
2296290037
|
@ -16,6 +16,12 @@ def gen_new(cls):
|
||||||
return __new__
|
return __new__
|
||||||
|
|
||||||
|
|
||||||
|
def gen_init(cls):
|
||||||
|
def __init__(self, value, mark):
|
||||||
|
return cls.__init__(self, value)
|
||||||
|
return __init__
|
||||||
|
|
||||||
|
|
||||||
class MarkedUnicode(unicode):
|
class MarkedUnicode(unicode):
|
||||||
__new__ = gen_new(unicode)
|
__new__ = gen_new(unicode)
|
||||||
|
|
||||||
|
@ -49,14 +55,17 @@ class MarkedFloat(float):
|
||||||
|
|
||||||
class MarkedDict(dict):
|
class MarkedDict(dict):
|
||||||
__new__ = gen_new(dict)
|
__new__ = gen_new(dict)
|
||||||
|
__init__ = gen_init(dict)
|
||||||
def __init__(self, value, mark):
|
|
||||||
super(MarkedDict, self).__init__(value)
|
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
return MarkedDict(super(MarkedDict, self).copy(), self.mark)
|
return MarkedDict(super(MarkedDict, self).copy(), self.mark)
|
||||||
|
|
||||||
|
|
||||||
|
class MarkedList(list):
|
||||||
|
__new__ = gen_new(list)
|
||||||
|
__init__ = gen_init(list)
|
||||||
|
|
||||||
|
|
||||||
class MarkedValue:
|
class MarkedValue:
|
||||||
def __init__(self, value, mark):
|
def __init__(self, value, mark):
|
||||||
self.mark = mark
|
self.mark = mark
|
||||||
|
@ -68,6 +77,7 @@ specialclasses = {
|
||||||
int: MarkedInt,
|
int: MarkedInt,
|
||||||
float: MarkedFloat,
|
float: MarkedFloat,
|
||||||
dict: MarkedDict,
|
dict: MarkedDict,
|
||||||
|
list: MarkedList,
|
||||||
}
|
}
|
||||||
|
|
||||||
classcache = {}
|
classcache = {}
|
||||||
|
|
Loading…
Reference in New Issue