super().__init__("bad backref")
class namedtype(type):
- pass
+ def __new__(cls, *args, typename=None, **kwargs):
+ self = super().__new__(cls, *args, **kwargs)
+ self.typename = typename
+ return self
class decoder(object):
def __init__(self):
return buf
buf[key] = self.loadtagged(fp, tag)
+ def makeobjtype(self, nm):
+ return namedtype(str(nm), (data.obj, object), {}, typename=nm)
+
def loadobj(self, fp, ref=False):
if ref:
refid = len(self.reftab)
nm = self.load(fp)
typ = self.namedtypes.get(nm)
if typ is None:
- typ = self.namedtypes[nm] = namedtype(str(nm), (data.obj, object), {})
- typ.typename = nm
+ typ = self.namedtypes[nm] = self.makeobjtype(nm)
ret = typ()
if ref:
self.reftab[refid] = ret