A
andrew cooke
Related to the above, Is there anything wrong with the following code to replace the *instance* rather than the class dict? It seems very crude, but appears to work.
Thanks,
Andrew
class TupleSuper:
def __new__(cls):
print('in new')
instance = object.__new__(cls)
instance.__dict__ = TupleDict(instance.__dict__)
return instance
class D(TupleSuper):
def __init__(self):
self.a = 1
if __name__ == '__main__':
d = D()
assert d.a == 1
d.a = 2
assert d.a == 2
d.a = 'three'
assert d.a == 'three'
print('woop')
Thanks,
Andrew
class TupleSuper:
def __new__(cls):
print('in new')
instance = object.__new__(cls)
instance.__dict__ = TupleDict(instance.__dict__)
return instance
class D(TupleSuper):
def __init__(self):
self.a = 1
if __name__ == '__main__':
d = D()
assert d.a == 1
d.a = 2
assert d.a == 2
d.a = 'three'
assert d.a == 'three'
print('woop')