Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
e99ebaed
Commit
e99ebaed
authored
Sep 12, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nicer error message for invalid function arguments
parent
b3794f10
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
17 additions
and
9 deletions
+17
-9
include/pybind11/pybind11.h
+4
-2
tests/test_callbacks.py
+1
-1
tests/test_inheritance.py
+2
-1
tests/test_issues.py
+6
-3
tests/test_kwargs_and_defaults.py
+2
-1
tests/test_opaque_types.py
+2
-1
No files found.
include/pybind11/pybind11.h
View file @
e99ebaed
...
...
@@ -460,8 +460,10 @@ protected:
if
(
overloads
->
is_operator
)
return
handle
(
Py_NotImplemented
).
inc_ref
().
ptr
();
std
::
string
msg
=
"Incompatible "
+
std
::
string
(
overloads
->
is_constructor
?
"constructor"
:
"function"
)
+
std
::
string
msg
=
std
::
string
(
overloads
->
name
)
+
"(): incompatible "
+
std
::
string
(
overloads
->
is_constructor
?
"constructor"
:
"function"
)
+
" arguments. The following argument types are supported:
\n
"
;
int
ctr
=
0
;
for
(
detail
::
function_record
*
it2
=
overloads
;
it2
!=
nullptr
;
it2
=
it2
->
next
)
{
msg
+=
" "
+
std
::
to_string
(
++
ctr
)
+
". "
;
...
...
@@ -489,7 +491,7 @@ protected:
msg
+=
"
\n
"
;
}
msg
+=
"
Invoked with: "
;
msg
+=
"
\n
Invoked with: "
;
tuple
args_
(
args
,
true
);
for
(
size_t
ti
=
overloads
->
is_constructor
?
1
:
0
;
ti
<
args_
.
size
();
++
ti
)
{
msg
+=
static_cast
<
std
::
string
>
(
static_cast
<
object
>
(
args_
[
ti
]).
str
());
...
...
tests/test_callbacks.py
View file @
e99ebaed
...
...
@@ -83,7 +83,7 @@ def test_cpp_function_roundtrip():
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
test_dummy_function
(
dummy_function2
)
assert
"
I
ncompatible function arguments"
in
str
(
excinfo
.
value
)
assert
"
i
ncompatible function arguments"
in
str
(
excinfo
.
value
)
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
test_dummy_function
(
lambda
x
,
y
:
x
+
y
)
...
...
tests/test_inheritance.py
View file @
e99ebaed
...
...
@@ -24,8 +24,9 @@ def test_inheritance(msg):
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
dog_bark
(
polly
)
assert
msg
(
excinfo
.
value
)
==
"""
I
ncompatible function arguments. The following argument types are supported:
dog_bark(): i
ncompatible function arguments. The following argument types are supported:
1. (arg0: m.Dog) -> str
Invoked with: <m.Pet object at 0>
"""
...
...
tests/test_issues.py
View file @
e99ebaed
...
...
@@ -65,16 +65,18 @@ def test_no_id(capture, msg):
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
get_element
(
None
)
assert
msg
(
excinfo
.
value
)
==
"""
I
ncompatible function arguments. The following argument types are supported:
get_element(): i
ncompatible function arguments. The following argument types are supported:
1. (arg0: m.issues.ElementA) -> int
Invoked with: None
"""
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
expect_int
(
5.2
)
assert
msg
(
excinfo
.
value
)
==
"""
I
ncompatible function arguments. The following argument types are supported:
expect_int(): i
ncompatible function arguments. The following argument types are supported:
1. (arg0: int) -> int
Invoked with: 5.2
"""
assert
expect_float
(
12
)
==
12
...
...
@@ -90,9 +92,10 @@ def test_str_issue(msg):
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
str
(
StrIssue
(
"no"
,
"such"
,
"constructor"
))
assert
msg
(
excinfo
.
value
)
==
"""
I
ncompatible constructor arguments. The following argument types are supported:
__init__(): i
ncompatible constructor arguments. The following argument types are supported:
1. m.issues.StrIssue(arg0: int)
2. m.issues.StrIssue()
Invoked with: no, such, constructor
"""
...
...
tests/test_kwargs_and_defaults.py
View file @
e99ebaed
...
...
@@ -35,8 +35,9 @@ def test_named_arguments(msg):
# noinspection PyArgumentList
kw_func2
(
x
=
5
,
y
=
10
,
z
=
12
)
assert
msg
(
excinfo
.
value
)
==
"""
I
ncompatible function arguments. The following argument types are supported:
kw_func2(): i
ncompatible function arguments. The following argument types are supported:
1. (x: int=100, y: int=200) -> str
Invoked with:
"""
...
...
tests/test_opaque_types.py
View file @
e99ebaed
...
...
@@ -35,8 +35,9 @@ def test_pointers(msg):
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
get_void_ptr_value
([
1
,
2
,
3
])
# This should not work
assert
msg
(
excinfo
.
value
)
==
"""
I
ncompatible function arguments. The following argument types are supported:
get_void_ptr_value(): i
ncompatible function arguments. The following argument types are supported:
1. (arg0: capsule) -> int
Invoked with: [1, 2, 3]
"""
...
...
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