New issue, when registering type multiple times.

Ideally, the module should fail when loading IMO.
This commit is contained in:
Andreas Bergmeier 2016-05-31 09:32:03 +02:00
parent 5eda97d7e4
commit e90bf7cc06
3 changed files with 29 additions and 0 deletions

View File

@ -131,4 +131,25 @@ void init_issues(py::module &m) {
.def("f", &A::f); .def("f", &A::f);
m2.def("call_f", call_f); m2.def("call_f", call_f);
{
struct DuplicateFoo {
int id() const { return 1; }
};
struct SingularBar : public DuplicateFoo {
};
pybind11::class_<DuplicateFoo>(m2, "DuplicateFoo")
.def_property_readonly("id", &DuplicateFoo::id)
;
pybind11::class_<SingularBar>(m2, "SingularBar")
.def(pybind11::init<>())
;
// Second time registration
pybind11::class_<DuplicateFoo>(m2, "DuplicateFoo")
;
}
} }

View File

@ -10,6 +10,7 @@ from example.issues import iterator_passthrough
from example.issues import ElementList, ElementA, print_element from example.issues import ElementList, ElementA, print_element
from example.issues import expect_float, expect_int from example.issues import expect_float, expect_int
from example.issues import A, call_f from example.issues import A, call_f
from example.issues import SingularBar
import gc import gc
print_cchar("const char *") print_cchar("const char *")
@ -72,3 +73,9 @@ print("Python version")
b = B() b = B()
call_f(b) call_f(b)
singularBar = SingularBar()
try:
singularBar.id
except Exception as e:
print("Failed as expected: " + str(e))

View File

@ -18,3 +18,4 @@ Python version
PyA.PyA() PyA.PyA()
PyA.f() PyA.f()
In python f() In python f()
Failed as expected: 'issues.SingularBar' object has no attribute 'id'