Replacing *instance* dict

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')
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top