This is an issue in a lot of places in SymPy (see
https://github.com/sympy/sympy/issues/6751). The solution is to always
reference the class indirectly via self, and make use of super(),
isinstance(), and issubclass() (the exception is that the class does
have to be named explicitly in the arguments to super()). You can use
self.__class__ or type(self). I'm not sure if one is better than the
other. If you see issues with this, please do submit pull requests
fixing them. We do want SymPy to be usable as a library, and an
important part of that is making classes subclassable.

Aaron Meurer

On Sat, Dec 6, 2014 at 4:17 PM, Duane Nykamp <[email protected]> wrote:
> The Point class, for numerous functions, such as .evalf, returns a hard
> coded Point class.  This means that for a derived class, these functions end
> up returning the original Point class not the derived class.  I assume there
> must be a way to code it differently so these functions return the derived
> class.  For now, I'm just overriding the functions, like .evalf, that I need
> to use so that they return my derived class.
>
> Should the calls to Point be changed to self.__class__ or is there a
> different way one is supposed to accomplish this in Python?  If it is as
> simple as that, I could make the change and submit a pull request.
>
> (I'm creating a derived class to get rid of the call to nsimplify, as
> functions like doit() and bottom up get rid of the evaluate=False flag.
> nsimplify is quite slow.  Each call to nsimplify for something like
> Point(3.23423545235,6.345436534630) takes on the order of 100 ms.  My
> webserver slowed to a crawl with 140 students repeatedly hitting "Submit"
> multiple times to check answers with a problem that had less than 10 Points
> in it.  Even with no load, the server takes over a second to grade the
> question and spit back the results.)
>
> Thanks,
> Duane
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/fbc166f3-0dd7-4111-9bd3-bbe9826460ce%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6Km0aJaP9L1ftq-vDbsTyCJozvU6iiS3MbmDGR3NNtk8w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to