0

I'm trying to create a transparent wrap: a class which passes all references (apart from some few) to one of its fields. I have got this:

class Wrap():

  def __init__(self,val,parent):
    self.__dict__['val']=val
    self.__dict__['parent']=parent

  def SetValue(self,val):
    self.__dict__['val']=val

  def __getattr__(self,attr):
    return  self.__dict__['val'].__getattribute__(attr)

  def __setattr__(self,attr,val):
    self.__dict__['val'].__setattribute__(attr,val)

The problem is that the wrap doesn't seems to pass __getitem__/__setitem__ calls and I get TypeError: 'Wrap' object does not support item assignment when I try subscript the wrap, although val is subscriptable. Is it any workaround?

valplo
  • 693
  • 5
  • 13
  • 1
    Unfortunately "magic" methods cannot be simply proxied. See the duplicate question for a way to make it work. I consider this one of the biggest outstanding warts in Python. – BrenBarn Jun 04 '14 at 20:03
  • Thank you very much. Should i delete my question? – valplo Jun 04 '14 at 20:05
  • No need to delete it, you can leave it as a signpost to the duplicate. – BrenBarn Jun 04 '14 at 20:14

0 Answers0