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):
2412
2412
class Function (Expr ):
2413
2413
2414
2414
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
+
2417
2424
return super (Function, cls ).__new__(cls )
2418
2425
2419
2426
@property
Original file line number Diff line number Diff line change @@ -103,6 +103,15 @@ def test_derivative():
103
103
assert i == fxy .diff (y , 1 , x )
104
104
105
105
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
+
106
115
def test_abs ():
107
116
x = Symbol ("x" )
108
117
e = abs (x )
You can’t perform that action at this time.
0 commit comments