18 m_sub.def(
"submodule_func", []() {
return "submodule_func()"; });
27 std::string toString() {
return "A[" + std::to_string(v) +
"]"; }
31 py::class_<A>(m_sub,
"A")
33 .def(
"__repr__", &A::toString);
41 A &get_a1() {
return a1; }
42 A &get_a2() {
return a2; }
47 py::class_<B>(m_sub,
"B")
49 .def(
"get_a1", &B::get_a1,
"Return the internal A 1", py::return_value_policy::reference_internal)
50 .def(
"get_a2", &B::get_a2,
"Return the internal A 2", py::return_value_policy::reference_internal)
51 .def_readwrite(
"a1", &B::a1)
52 .def_readwrite(
"a2", &B::a2);
55 m.attr(
"OD") = py::module::import(
"collections").attr(
"OrderedDict");
59 m.def(
"duplicate_registration", []() {
63 class DupeException { };
66 auto dm = py::module_::create_extension_module(
"dummy",
nullptr,
new py::module_::module_def);
67 auto failures = py::list();
69 py::class_<Dupe1>(dm,
"Dupe1");
70 py::class_<Dupe2>(dm,
"Dupe2");
71 dm.def(
"dupe1_factory", []() {
return Dupe1(); });
72 py::exception<DupeException>(dm,
"DupeException");
75 py::class_<Dupe1>(dm,
"Dupe1");
76 failures.append(
"Dupe1 class");
77 }
catch (std::runtime_error &) {}
79 dm.def(
"Dupe1", []() {
return Dupe1(); });
80 failures.append(
"Dupe1 function");
81 }
catch (std::runtime_error &) {}
83 py::class_<Dupe3>(dm,
"dupe1_factory");
84 failures.append(
"dupe1_factory");
85 }
catch (std::runtime_error &) {}
87 py::exception<Dupe3>(dm,
"Dupe2");
88 failures.append(
"Dupe2");
89 }
catch (std::runtime_error &) {}
91 dm.def(
"DupeException", []() {
return 30; });
92 failures.append(
"DupeException1");
93 }
catch (std::runtime_error &) {}
95 py::class_<DupeException>(dm,
"DupeException");
96 failures.append(
"DupeException2");
97 }
catch (std::runtime_error &) {}