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
2cf87a54
Commit
2cf87a54
authored
Sep 10, 2017
by
Dean Moldovan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix implicit conversion of accessors to types derived from py::object
Fixes #1069.
parent
953d2422
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
3 deletions
+13
-3
include/pybind11/pytypes.h
+5
-3
tests/test_pytypes.cpp
+6
-0
tests/test_pytypes.py
+2
-0
No files found.
include/pybind11/pytypes.h
View file @
2cf87a54
...
...
@@ -431,8 +431,8 @@ class accessor : public object_api<accessor<Policy>> {
public
:
accessor
(
handle
obj
,
key_type
key
)
:
obj
(
obj
),
key
(
std
::
move
(
key
))
{
}
accessor
(
const
accessor
&
a
)
=
default
;
accessor
(
accessor
&&
a
)
=
default
;
accessor
(
const
accessor
&
)
=
default
;
accessor
(
accessor
&&
)
=
default
;
// accessor overload required to override default assignment operator (templates are not allowed
// to replace default compiler-generated assignments).
...
...
@@ -743,7 +743,9 @@ NAMESPACE_END(detail)
{ if (!m_ptr) throw error_already_set(); } \
Name(object &&o) \
: Parent(check_(o) ? o.release().ptr() : ConvertFun(o.ptr()), stolen_t{}) \
{ if (!m_ptr) throw error_already_set(); }
{ if (!m_ptr) throw error_already_set(); } \
template <typename Policy_> \
Name(const ::pybind11::detail::accessor<Policy_> &a) : Name(object(a)) { }
#define PYBIND11_OBJECT(Name, Parent, CheckFun) \
PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \
...
...
tests/test_pytypes.cpp
View file @
2cf87a54
...
...
@@ -128,6 +128,12 @@ TEST_SUBMODULE(pytypes, m) {
d
[
"operator()"
]
=
o
.
attr
(
"func"
)(
1
);
d
[
"operator*"
]
=
o
.
attr
(
"func"
)(
*
o
.
attr
(
"begin_end"
));
// Test implicit conversion
py
::
list
implicit_list
=
o
.
attr
(
"begin_end"
);
d
[
"implicit_list"
]
=
implicit_list
;
py
::
dict
implicit_dict
=
o
.
attr
(
"__dict__"
);
d
[
"implicit_dict"
]
=
implicit_dict
;
return
d
;
});
...
...
tests/test_pytypes.py
View file @
2cf87a54
...
...
@@ -144,6 +144,8 @@ def test_accessors():
assert
d
[
"is_none"
]
is
False
assert
d
[
"operator()"
]
==
2
assert
d
[
"operator*"
]
==
7
assert
d
[
"implicit_list"
]
==
[
1
,
2
,
3
]
assert
all
(
x
in
TestObject
.
__dict__
for
x
in
d
[
"implicit_dict"
])
assert
m
.
tuple_accessor
(
tuple
())
==
(
0
,
1
,
2
)
...
...
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