Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
111b2f0a
Commit
111b2f0a
authored
Jun 24, 2017
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
repair error message when calling fused functions with wrong number of arguments
parent
22fc174e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
5 deletions
+24
-5
Cython/Compiler/FusedNode.py
Cython/Compiler/FusedNode.py
+12
-3
tests/run/fused_cpdef.pyx
tests/run/fused_cpdef.pyx
+6
-0
tests/run/fused_def.pyx
tests/run/fused_def.pyx
+6
-2
No files found.
Cython/Compiler/FusedNode.py
View file @
111b2f0a
...
...
@@ -516,7 +516,12 @@ class FusedCFuncDefNode(StatListNode):
{{if arg.default}}
arg = (<tuple>defaults)[{{default_idx}}]
{{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}}
"""
)
...
...
@@ -536,6 +541,10 @@ class FusedCFuncDefNode(StatListNode):
'memviewslice_cname'
:
MemoryView
.
memviewslice_cname
,
'func_args'
:
self
.
node
.
args
,
'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
,
}
...
...
@@ -629,9 +638,9 @@ class FusedCFuncDefNode(StatListNode):
match_found = False
src_sig = sig.strip('()').split('|')
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 src_
type
== dst_type:
if src_
sig[i]
== dst_type:
match_found = True
else:
match_found = False
...
...
tests/run/fused_cpdef.pyx
View file @
111b2f0a
...
...
@@ -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 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
[
cy
.
int
,
cy
.
float
](
1
,
2.0
)
...
...
tests/run/fused_def.pyx
View file @
111b2f0a
...
...
@@ -105,11 +105,15 @@ def opt_func(fused_t obj, cython.floating myf = 1.2, cython.integral myi = 7):
>>> opt_func(object(), f)
Traceback (most recent call last):
...
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)
Traceback (most recent call last):
...
TypeError: Argument 'obj' has incorrect type (expected fused_def.ExtClassA, got object)
"""
print
cython
.
typeof
(
obj
),
cython
.
typeof
(
myf
),
cython
.
typeof
(
myi
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment