@@ -81,21 +81,22 @@ def call_function(self, function_name, resolved_args):
81
81
return function (self , * resolved_args )
82
82
83
83
def _validate_arguments (self , args , signature , function_name ):
84
- if signature and signature [- 1 ].get ('variadic' ):
85
- if len (args ) < len (signature ):
86
- raise exceptions .VariadictArityError (
87
- len (signature ), len (args ), function_name )
88
- elif len (args ) != len (signature ):
89
- raise exceptions .ArityError (
90
- len (signature ), len (args ), function_name )
91
- return self ._type_check (args , signature , function_name )
84
+ min_args = sum (1 for sig in signature if not sig .get ('optional' , False ))
85
+ if len (args ) < min_args :
86
+ raise exceptions .ArityError (min_args , len (args ), function_name )
87
+
88
+ if len (args ) > len (signature ) and not signature [- 1 ].get ('variadic' ):
89
+ raise exceptions .ArityError (len (signature ), len (args ), function_name )
90
+
91
+ self ._type_check (args , signature , function_name )
92
+
92
93
93
94
def _type_check (self , actual , signature , function_name ):
94
- for i in range (len (signature )):
95
+ for i in range (len (actual )):
95
96
allowed_types = signature [i ]['types' ]
96
- if allowed_types :
97
- self ._type_check_single (actual [i ], allowed_types ,
98
- function_name )
97
+ if allowed_types and not ( signature [ i ]. get ( 'optional' ) and actual [ i ] is None ) :
98
+ self ._type_check_single (actual [i ], allowed_types , function_name )
99
+
99
100
100
101
def _type_check_single (self , current , types , function_name ):
101
102
# Type checking involves checking the top level type,
0 commit comments