It was specially annoying that you could not return list or tuples. I don't know the reason of this behaviour, fortunately changing it did not break any tests.
I added a test for this --- sympy/core/function.py | 17 ++++++----------- sympy/core/tests/test_functions.py | 7 +++++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/sympy/core/function.py b/sympy/core/function.py index aae869d..8331751 100644 --- a/sympy/core/function.py +++ b/sympy/core/function.py @@ -138,18 +138,13 @@ def __new__(cls, *args, **options): # up to here. if options.get('evaluate') is False: return Basic.__new__(cls, *args, **options) - r = cls.eval(*args) - if isinstance(r, Basic): + evaluated = cls.eval(*args) + if evaluated is not None: return evaluated + # Just undefined functions have nargs == None + if not cls.nargs and hasattr(cls, 'undefined_Function'): + r = Basic.__new__(cls, *args, **options) + r.nargs = len(args) return r - elif r is None: - # Just undefined functions have nargs == None - if not cls.nargs and hasattr(cls, 'undefined_Function'): - r = Basic.__new__(cls, *args, **options) - r.nargs = len(args) - return r - pass - elif not isinstance(r, tuple): - args = (r,) return Basic.__new__(cls, *args, **options) @property diff --git a/sympy/core/tests/test_functions.py b/sympy/core/tests/test_functions.py index 8d7d165..94b08a6 100644 --- a/sympy/core/tests/test_functions.py +++ b/sympy/core/tests/test_functions.py @@ -290,3 +290,10 @@ def eq(a,b,eps): assert eq(exp(-0.5+1.5*I).evalf(15), Real("0.0429042815937374") + Real("0.605011292285002")*I, 1e-13) assert eq(log(pi+sqrt(2)*I).evalf(15), Real("1.23699044022052") + Real("0.422985442737893")*I, 1e-13) assert eq(cos(100).evalf(15), Real("0.86231887228768"), 1e-13) + +def test_extensibility_eval(): + class MyFunc(Function): + @classmethod + def eval(cls, *args): + return (0,0,0) + assert MyFunc(0) == (0,0,0) \ No newline at end of file -- 1.6.1.2 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy-patches" group. To post to this group, send email to sympy-patches@googlegroups.com To unsubscribe from this group, send email to sympy-patches+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sympy-patches?hl=en -~----------~----~----~----~------~----~------~--~---