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
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
24 additions
and
16 deletions
+24
-16
include/pybind11/pybind11.h
+5
-3
tests/test_callbacks.py
+1
-1
tests/test_inheritance.py
+3
-2
tests/test_issues.py
+9
-6
tests/test_kwargs_and_defaults.py
+3
-2
tests/test_opaque_types.py
+3
-2
No files found.
include/pybind11/pybind11.h
View file @
e99ebaed
...
@@ -460,8 +460,10 @@ protected:
...
@@ -460,8 +460,10 @@ protected:
if
(
overloads
->
is_operator
)
if
(
overloads
->
is_operator
)
return
handle
(
Py_NotImplemented
).
inc_ref
().
ptr
();
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 "
+
" arguments. The following argument types are supported:
\n
"
;
std
::
string
(
overloads
->
is_constructor
?
"constructor"
:
"function"
)
+
" arguments. The following argument types are supported:
\n
"
;
int
ctr
=
0
;
int
ctr
=
0
;
for
(
detail
::
function_record
*
it2
=
overloads
;
it2
!=
nullptr
;
it2
=
it2
->
next
)
{
for
(
detail
::
function_record
*
it2
=
overloads
;
it2
!=
nullptr
;
it2
=
it2
->
next
)
{
msg
+=
" "
+
std
::
to_string
(
++
ctr
)
+
". "
;
msg
+=
" "
+
std
::
to_string
(
++
ctr
)
+
". "
;
...
@@ -489,7 +491,7 @@ protected:
...
@@ -489,7 +491,7 @@ protected:
msg
+=
"
\n
"
;
msg
+=
"
\n
"
;
}
}
msg
+=
"
Invoked with: "
;
msg
+=
"
\n
Invoked with: "
;
tuple
args_
(
args
,
true
);
tuple
args_
(
args
,
true
);
for
(
size_t
ti
=
overloads
->
is_constructor
?
1
:
0
;
ti
<
args_
.
size
();
++
ti
)
{
for
(
size_t
ti
=
overloads
->
is_constructor
?
1
:
0
;
ti
<
args_
.
size
();
++
ti
)
{
msg
+=
static_cast
<
std
::
string
>
(
static_cast
<
object
>
(
args_
[
ti
]).
str
());
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():
...
@@ -83,7 +83,7 @@ def test_cpp_function_roundtrip():
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
test_dummy_function
(
dummy_function2
)
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
:
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
test_dummy_function
(
lambda
x
,
y
:
x
+
y
)
test_dummy_function
(
lambda
x
,
y
:
x
+
y
)
...
...
tests/test_inheritance.py
View file @
e99ebaed
...
@@ -24,9 +24,10 @@ def test_inheritance(msg):
...
@@ -24,9 +24,10 @@ def test_inheritance(msg):
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
dog_bark
(
polly
)
dog_bark
(
polly
)
assert
msg
(
excinfo
.
value
)
==
"""
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
1. (arg0: m.Dog) -> str
Invoked with: <m.Pet object at 0>
Invoked with: <m.Pet object at 0>
"""
"""
...
...
tests/test_issues.py
View file @
e99ebaed
...
@@ -65,17 +65,19 @@ def test_no_id(capture, msg):
...
@@ -65,17 +65,19 @@ def test_no_id(capture, msg):
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
get_element
(
None
)
get_element
(
None
)
assert
msg
(
excinfo
.
value
)
==
"""
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
1. (arg0: m.issues.ElementA) -> int
Invoked with: None
Invoked with: None
"""
"""
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
expect_int
(
5.2
)
expect_int
(
5.2
)
assert
msg
(
excinfo
.
value
)
==
"""
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
1. (arg0: int) -> int
Invoked with: 5.2
Invoked with: 5.2
"""
"""
assert
expect_float
(
12
)
==
12
assert
expect_float
(
12
)
==
12
...
@@ -90,10 +92,11 @@ def test_str_issue(msg):
...
@@ -90,10 +92,11 @@ def test_str_issue(msg):
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
str
(
StrIssue
(
"no"
,
"such"
,
"constructor"
))
str
(
StrIssue
(
"no"
,
"such"
,
"constructor"
))
assert
msg
(
excinfo
.
value
)
==
"""
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)
1. m.issues.StrIssue(arg0: int)
2. m.issues.StrIssue()
2. m.issues.StrIssue()
Invoked with: no, such, constructor
Invoked with: no, such, constructor
"""
"""
...
...
tests/test_kwargs_and_defaults.py
View file @
e99ebaed
...
@@ -35,9 +35,10 @@ def test_named_arguments(msg):
...
@@ -35,9 +35,10 @@ def test_named_arguments(msg):
# noinspection PyArgumentList
# noinspection PyArgumentList
kw_func2
(
x
=
5
,
y
=
10
,
z
=
12
)
kw_func2
(
x
=
5
,
y
=
10
,
z
=
12
)
assert
msg
(
excinfo
.
value
)
==
"""
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
1. (x: int=100, y: int=200) -> str
Invoked with:
Invoked with:
"""
"""
assert
kw_func4
()
==
"{13 17}"
assert
kw_func4
()
==
"{13 17}"
...
...
tests/test_opaque_types.py
View file @
e99ebaed
...
@@ -35,9 +35,10 @@ def test_pointers(msg):
...
@@ -35,9 +35,10 @@ def test_pointers(msg):
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
get_void_ptr_value
([
1
,
2
,
3
])
# This should not work
get_void_ptr_value
([
1
,
2
,
3
])
# This should not work
assert
msg
(
excinfo
.
value
)
==
"""
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
1. (arg0: capsule) -> int
Invoked with: [1, 2, 3]
Invoked with: [1, 2, 3]
"""
"""
assert
return_null_str
()
is
None
assert
return_null_str
()
is
None
...
...
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