Generally of Function should override the class method eval, like
class MyClass(Function):
@classmethod
def eval(cls, *args):
return an alternate object, or None to remain unevaluated
This automatically puts the *args in the object's .args. If you want to
handle non-SymPy objects like Python functions, you'll have to handle those
outside of .args.
I think for what you want, you need to use __new__. Don't forget to use
super() to call the superclass __new__ in your subclass.
Aaron Meurer
On Tue, Jul 14, 2015 at 9:07 AM, Nico <[email protected]> wrote:
> This question is connected to my previous question [1].
>
> I'd like to derive from `sympy.Function` and add some extra information to
> the class. This works:
> ```
> import sympy
> class MyTest(sympy.Function):
> def __init__(self, name):
> return
> a = MyTest('a')
> a.fun = lambda x: x
> ```
> It'd be easier to add the function definition straight in the initializer.
> However
> ```
> class MyTest(sympy.Function):
> def __init__(self, name, fun):
> self.fun = fun
> return
> a = MyTest('a', lambda x: x)
> ```
> does *not* work.
>
> Any idea why that is and how to fix it?
>
> Cheers,
> Nico
>
>
> [1] https://groups.google.com/forum/#!topic/sympy/Iks7BQU_VgA
>
> --
> 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/0b42776b-8a49-4d34-adaf-f722d6075a0f%40googlegroups.com
> <https://groups.google.com/d/msgid/sympy/0b42776b-8a49-4d34-adaf-f722d6075a0f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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%3D6KM7UocBgbH9nG%3DcCLUh-%3DJvqpHp%3DmvT7E2bFcuzy22-A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.