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
8b51ed17
Commit
8b51ed17
authored
Oct 14, 2016
by
Wenzel Jakob
Committed by
GitHub
Oct 14, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #444 from dean0x7d/inherit-dynamic-attr
Fix dynamic attribute inheritance in C++
parents
5c13749a
b8cb5ca7
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
3 deletions
+12
-3
include/pybind11/attr.h
+3
-0
tests/test_methods_and_attributes.cpp
+5
-0
tests/test_methods_and_attributes.py
+4
-3
No files found.
include/pybind11/attr.h
View file @
8b51ed17
...
@@ -179,6 +179,9 @@ struct type_record {
...
@@ -179,6 +179,9 @@ struct type_record {
bases
.
append
((
PyObject
*
)
base_info
->
type
);
bases
.
append
((
PyObject
*
)
base_info
->
type
);
if
(
base_info
->
type
->
tp_dictoffset
!=
0
)
dynamic_attr
=
true
;
if
(
caster
)
if
(
caster
)
base_info
->
implicit_casts
.
push_back
(
std
::
make_pair
(
type
,
caster
));
base_info
->
implicit_casts
.
push_back
(
std
::
make_pair
(
type
,
caster
));
}
}
...
...
tests/test_methods_and_attributes.cpp
View file @
8b51ed17
...
@@ -59,6 +59,8 @@ public:
...
@@ -59,6 +59,8 @@ public:
~
DynamicClass
()
{
print_destroyed
(
this
);
}
~
DynamicClass
()
{
print_destroyed
(
this
);
}
};
};
class
CppDerivedDynamicClass
:
public
DynamicClass
{
};
test_initializer
methods_and_attributes
([](
py
::
module
&
m
)
{
test_initializer
methods_and_attributes
([](
py
::
module
&
m
)
{
py
::
class_
<
ExampleMandA
>
(
m
,
"ExampleMandA"
)
py
::
class_
<
ExampleMandA
>
(
m
,
"ExampleMandA"
)
.
def
(
py
::
init
<>
())
.
def
(
py
::
init
<>
())
...
@@ -90,4 +92,7 @@ test_initializer methods_and_attributes([](py::module &m) {
...
@@ -90,4 +92,7 @@ test_initializer methods_and_attributes([](py::module &m) {
py
::
class_
<
DynamicClass
>
(
m
,
"DynamicClass"
,
py
::
dynamic_attr
())
py
::
class_
<
DynamicClass
>
(
m
,
"DynamicClass"
,
py
::
dynamic_attr
())
.
def
(
py
::
init
());
.
def
(
py
::
init
());
py
::
class_
<
CppDerivedDynamicClass
,
DynamicClass
>
(
m
,
"CppDerivedDynamicClass"
)
.
def
(
py
::
init
());
});
});
tests/test_methods_and_attributes.py
View file @
8b51ed17
...
@@ -48,7 +48,7 @@ def test_methods_and_attributes():
...
@@ -48,7 +48,7 @@ def test_methods_and_attributes():
def
test_dynamic_attributes
():
def
test_dynamic_attributes
():
from
pybind11_tests
import
DynamicClass
from
pybind11_tests
import
DynamicClass
,
CppDerivedDynamicClass
instance
=
DynamicClass
()
instance
=
DynamicClass
()
assert
not
hasattr
(
instance
,
"foo"
)
assert
not
hasattr
(
instance
,
"foo"
)
...
@@ -76,10 +76,11 @@ def test_dynamic_attributes():
...
@@ -76,10 +76,11 @@ def test_dynamic_attributes():
assert
cstats
.
alive
()
==
0
assert
cstats
.
alive
()
==
0
# Derived classes should work as well
# Derived classes should work as well
class
Derived
(
DynamicClass
):
class
PythonDerivedDynamicClass
(
DynamicClass
):
pass
pass
derived
=
Derived
()
for
cls
in
CppDerivedDynamicClass
,
PythonDerivedDynamicClass
:
derived
=
cls
()
derived
.
foobar
=
100
derived
.
foobar
=
100
assert
derived
.
foobar
==
100
assert
derived
.
foobar
==
100
...
...
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