Commit 111b2f0a authored by Stefan Behnel's avatar Stefan Behnel

repair error message when calling fused functions with wrong number of arguments

parent 22fc174e
...@@ -516,7 +516,12 @@ class FusedCFuncDefNode(StatListNode): ...@@ -516,7 +516,12 @@ class FusedCFuncDefNode(StatListNode):
{{if arg.default}} {{if arg.default}}
arg = (<tuple>defaults)[{{default_idx}}] arg = (<tuple>defaults)[{{default_idx}}]
{{else}} {{else}}
raise TypeError("Expected at least %d arguments" % len(<tuple>args)) {{if arg_tuple_idx < min_positional_args}}
raise TypeError("Expected at least %d argument%s, got %d" % (
{{min_positional_args}}, {{'"s"' if min_positional_args != 1 else '""'}}, len(<tuple>args)))
{{else}}
raise TypeError("Missing keyword-only argument: '%s'" % "{{arg.default}}")
{{endif}}
{{endif}} {{endif}}
""") """)
...@@ -536,6 +541,10 @@ class FusedCFuncDefNode(StatListNode): ...@@ -536,6 +541,10 @@ class FusedCFuncDefNode(StatListNode):
'memviewslice_cname': MemoryView.memviewslice_cname, 'memviewslice_cname': MemoryView.memviewslice_cname,
'func_args': self.node.args, 'func_args': self.node.args,
'n_fused': len(fused_types), 'n_fused': len(fused_types),
'min_positional_args':
self.node.num_required_args - self.node.num_required_kw_args
if is_def else
sum(1 for arg in self.node.args if arg.default is None),
'name': orig_py_func.entry.name, 'name': orig_py_func.entry.name,
} }
...@@ -629,9 +638,9 @@ class FusedCFuncDefNode(StatListNode): ...@@ -629,9 +638,9 @@ class FusedCFuncDefNode(StatListNode):
match_found = False match_found = False
src_sig = sig.strip('()').split('|') src_sig = sig.strip('()').split('|')
for i in range(len(dest_sig)): for i in range(len(dest_sig)):
src_type, dst_type = src_sig[i], dest_sig[i] dst_type = dest_sig[i]
if dst_type is not None: if dst_type is not None:
if src_type == dst_type: if src_sig[i] == dst_type:
match_found = True match_found = True
else: else:
match_found = False match_found = False
......
...@@ -94,6 +94,12 @@ def test_multiarg(): ...@@ -94,6 +94,12 @@ def test_multiarg():
x is an int, y is a float: 1 2.0 x is an int, y is a float: 1 2.0
x is an int, y is a float: 1 2.0 x is an int, y is a float: 1 2.0
x is a long, y is a double: 4 5.0 x is a long, y is a double: 4 5.0
>>> multiarg()
Traceback (most recent call last):
TypeError: Expected at least 2 arguments, got 0
>>> multiarg(1, 2.0, 3) # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...2...arg...3...
""" """
multiarg[int, float](1, 2.0) multiarg[int, float](1, 2.0)
multiarg[cy.int, cy.float](1, 2.0) multiarg[cy.int, cy.float](1, 2.0)
......
...@@ -105,11 +105,15 @@ def opt_func(fused_t obj, cython.floating myf = 1.2, cython.integral myi = 7): ...@@ -105,11 +105,15 @@ def opt_func(fused_t obj, cython.floating myf = 1.2, cython.integral myi = 7):
>>> opt_func(object(), f) >>> opt_func(object(), f)
Traceback (most recent call last): Traceback (most recent call last):
...
TypeError: Function call with ambiguous argument types TypeError: Function call with ambiguous argument types
>>> opt_func()
Traceback (most recent call last):
TypeError: Expected at least 1 argument, got 0
>>> opt_func("abc", f, i, 5) # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...at most 3...
>>> opt_func[ExtClassA, cy.float, cy.long](object(), f) >>> opt_func[ExtClassA, cy.float, cy.long](object(), f)
Traceback (most recent call last): Traceback (most recent call last):
...
TypeError: Argument 'obj' has incorrect type (expected fused_def.ExtClassA, got object) TypeError: Argument 'obj' has incorrect type (expected fused_def.ExtClassA, got object)
""" """
print cython.typeof(obj), cython.typeof(myf), cython.typeof(myi) print cython.typeof(obj), cython.typeof(myf), cython.typeof(myi)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment