File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -2412,8 +2412,15 @@ class Pow(Expr):
24122412class Function (Expr ):
24132413
24142414 def __new__ (cls , *args , **kwargs ):
2415- if cls == Function and len (args) == 1 :
2416- return UndefFunction(args[0 ])
2415+ if cls == Function:
2416+ nargs = len (args)
2417+ if nargs == 0 :
2418+ raise TypeError (" Required at least one argument to Function" )
2419+ elif nargs == 1 :
2420+ return UndefFunction(args[0 ])
2421+ elif nargs > 1 :
2422+ raise TypeError (f" Unexpected extra arguments {args[1:]}." )
2423+
24172424 return super (Function, cls ).__new__(cls )
24182425
24192426 @property
Original file line number Diff line number Diff line change @@ -103,6 +103,15 @@ def test_derivative():
103103 assert i == fxy .diff (y , 1 , x )
104104
105105
106+ def test_function ():
107+ x = Symbol ("x" )
108+ assert Function ("f" )(x ) == function_symbol ("f" , x )
109+
110+ raises (TypeError , lambda : Function ("f" , "x" ))
111+ raises (TypeError , lambda : Function ("f" , x ))
112+ raises (TypeError , lambda : Function ())
113+
114+
106115def test_abs ():
107116 x = Symbol ("x" )
108117 e = abs (x )
You can’t perform that action at this time.
0 commit comments