The place where the func and args attribute is set for sympy objects

29 views
Skip to first unread message

Tschijnmo Tschau

unread,
Mar 13, 2014, 1:32:47 AM3/13/14
to sy...@googlegroups.com
Hi all there in the Sympy group,

I am a student who have recently started to understand the Sympy code. From the advanced expression manipulation section in the tutorial, it is stated that basically all expressions in Sympy have got func and args attributes with which the object can be reconstructed, like in the Basic class, the copy method is defined in this way. But something that looks very curious to me is that for several typical sympy classes, like Add, Mul, and Symbol, it seems hat I cannot find the place where these two important attributes are set... For example, Add does not come with a __new__ method, I guess it is going to inherit the method from AssocOp, whose __new__ essentially delegated the work to cls._from_args. It seems that Add does not provide an override for this _from_args method, so maybe the _from_args of AssocOp is going to be invoked. But this method just used the __new__ method that is in the super class of AssocOp. It looks like AssocOp only have got one level of super class in Sympy, the Basic class, whose constructor sets the _args attribute but not for the func and args attribute. Since pdb does not seem to provide a feature like watch in gdb, I am very confused and curious where these two important attributes are actually set in the code. Any hint is deeply appreciated. Thank you so much!

Regards,

Tschijnmo

Sergey Kirpichev

unread,
Mar 13, 2014, 10:39:25 AM3/13/14
to sy...@googlegroups.com

On Thursday, March 13, 2014 9:32:47 AM UTC+4, Tschijnmo Tschau wrote:
It looks like AssocOp only have got one level of super class in Sympy, the Basic class, whose constructor sets the _args attribute but not for the func and args attribute.

The Basic class has *properties* func and args (@property decorator).

Tschijnmo Tschau

unread,
Mar 13, 2014, 3:30:29 PM3/13/14
to sy...@googlegroups.com
Okay, I got it! Thank you so much for your help!
Reply all
Reply to author
Forward
0 new messages