I'm not the best person to answer this, but probably you are doing this the wrong way. I suppose to know how you should do it, I would need to know more about how you expect this class to work. What do you expect BeamParamter(0, 1) to return? How about BeamParameter(BeamParameter(x, y), z) (nested classes)?
Aaron Meurer On Fri, Jun 10, 2011 at 12:10 PM, [email protected] <[email protected]> wrote: > Hi, > > I am trying to create a class that is basically the sum of two arguments > given in the constructor. Here is what I have done (simplified example with > omitted arguments and slots): > > class BeamParameter(Add): > > __slots__ = ['x', 'y'] > > def __new__(cls, x, y): > obj = Add.__new__(cls, x, I*y) > obj.x = x > obj.y = y > return obj > > > It works ok when Add returns Add: >>>>q=BeamParameter(1,1) >>>>q > 1+I*1 > > But it fails when Add returns Mul: >>>>q=BeamParameter(0,1) > ---> 54 obj.x = x > AttributeError: 'Mul' object has no attribute 'x' > > > The __slots__ are lost somewhere for some reason. I'm afraid that I don't > understand why. Maybe I should not use Add as a superclass. Do you have any > solutions? > > Stefan > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/sympy?hl=en. > -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
