Add MarkedList type

This commit is contained in:
ZyX 2014-07-12 23:21:16 +04:00
parent f482eea8be
commit 2296290037
1 changed files with 13 additions and 3 deletions

View File

@ -16,6 +16,12 @@ def gen_new(cls):
return __new__
def gen_init(cls):
def __init__(self, value, mark):
return cls.__init__(self, value)
return __init__
class MarkedUnicode(unicode):
__new__ = gen_new(unicode)
@ -49,14 +55,17 @@ class MarkedFloat(float):
class MarkedDict(dict):
__new__ = gen_new(dict)
def __init__(self, value, mark):
super(MarkedDict, self).__init__(value)
__init__ = gen_init(dict)
def copy(self):
return MarkedDict(super(MarkedDict, self).copy(), self.mark)
class MarkedList(list):
__new__ = gen_new(list)
__init__ = gen_init(list)
class MarkedValue:
def __init__(self, value, mark):
self.mark = mark
@ -68,6 +77,7 @@ specialclasses = {
int: MarkedInt,
float: MarkedFloat,
dict: MarkedDict,
list: MarkedList,
}
classcache = {}