14 #if !defined(PYBIND11_OVERLOAD_CAST)
15 template <
typename... Args>
29 return "ExampleMandA[value=" + std::to_string(
value) +
"]";
63 py::str
overloaded(
int,
float) {
return "(int, float)"; }
64 py::str
overloaded(
float,
int) {
return "(float, int)"; }
66 py::str
overloaded(
float,
float) {
return "(float, float)"; }
68 py::str
overloaded(
int,
float)
const {
return "(int, float) const"; }
69 py::str
overloaded(
float,
int)
const {
return "(float, int) const"; }
70 py::str
overloaded(
int,
int)
const {
return "(int, int) const"; }
71 py::str
overloaded(
float,
float)
const {
return "(float, float) const"; }
73 static py::str
overloaded(
float) {
return "static float"; }
102 const UserType &
get1()
const {
return v1; }
103 const UserType &
get2()
const {
return v2; }
115 int none3(std::shared_ptr<NoneTester> &obj) {
return obj ? obj->
answer : -1; }
116 int none4(std::shared_ptr<NoneTester> *obj) {
return obj && *obj ? (*obj)->
answer : -1; }
117 int none5(std::shared_ptr<NoneTester> obj) {
return obj ? obj->
answer : -1; }
139 using UnregisteredBase::UnregisteredBase;
153 py::class_<ExampleMandA> emna(
m,
"ExampleMandA");
154 emna.def(py::init<>())
155 .def(py::init<int>())
156 .def(py::init<std::string&&>())
157 .def(py::init<const ExampleMandA&>())
179 #if defined(PYBIND11_OVERLOAD_CAST)
209 .def_static(
"add_mixed_overloads1", []() {
210 auto emna = py::reinterpret_borrow<py::class_<ExampleMandA>>(py::module_::import(
"pybind11_tests.methods_and_attributes").attr(
"ExampleMandA"));
214 .def_static(
"add_mixed_overloads2", []() {
215 auto emna = py::reinterpret_borrow<py::class_<ExampleMandA>>(py::module_::import(
"pybind11_tests.methods_and_attributes").attr(
"ExampleMandA"));
224 emna.attr(
"add2b") = emna.attr(
"add2");
227 py::class_<TestProperties>(
m,
"TestProperties")
231 .def_property(
"def_writeonly",
nullptr,
236 .def_property(
"def_property_impossible",
nullptr,
nullptr)
239 .def_property_static(
"def_writeonly_static",
nullptr,
241 .def_property_readonly_static(
"def_property_readonly_static",
243 .def_property_static(
"def_property_writeonly_static",
nullptr,
245 .def_property_static(
"def_property_static",
248 .def_property_static(
"static_cls",
249 [](py::object cls) {
return cls; },
250 [](py::object cls, py::function f) { f(cls); });
252 py::class_<TestPropertiesOverride, TestProperties>(
m,
"TestPropertiesOverride")
257 auto static_get1 = [](py::object) ->
const UserType & {
return TestPropRVP::sv1; };
258 auto static_get2 = [](py::object) ->
const UserType & {
return TestPropRVP::sv2; };
261 auto rvp_copy = py::return_value_policy::copy;
264 py::class_<TestPropRVP>(
m,
"TestPropRVP")
268 .def_property_readonly(
"ro_func", py::cpp_function(&
TestPropRVP::get2, rvp_copy))
272 .def_property_readonly_static(
"static_ro_ref", static_get1)
273 .def_property_readonly_static(
"static_ro_copy", static_get2, rvp_copy)
274 .def_property_readonly_static(
"static_ro_func", py::cpp_function(static_get2, rvp_copy))
275 .def_property_static(
"static_rw_ref", static_get1, static_set1)
276 .def_property_static(
"static_rw_copy", static_get2, static_set2, rvp_copy)
277 .def_property_static(
"static_rw_func", py::cpp_function(static_get2, rvp_copy), static_set2)
280 .def_property_readonly_static(
"static_rvalue", [](py::object) {
return UserType(1); });
283 struct MetaclassOverride { };
284 py::class_<MetaclassOverride>(
m,
"MetaclassOverride", py::metaclass((PyObject *) &PyType_Type))
285 .def_property_readonly_static(
"readonly", [](py::object) {
return 1; });
288 m.def(
"overload_order", [](std::string) {
return 1; });
289 m.def(
"overload_order", [](std::string) {
return 2; });
290 m.def(
"overload_order", [](
int) {
return 3; });
291 m.def(
"overload_order", [](
int) {
return 4; }, py::prepend{});
293 #if !defined(PYPY_VERSION)
298 DynamicClass(
const DynamicClass&) =
delete;
301 py::class_<DynamicClass>(
m,
"DynamicClass", py::dynamic_attr())
304 class CppDerivedDynamicClass :
public DynamicClass { };
305 py::class_<CppDerivedDynamicClass, DynamicClass>(
m,
"CppDerivedDynamicClass")
312 m.attr(
"debug_enabled") =
true;
314 m.attr(
"debug_enabled") =
false;
316 m.def(
"bad_arg_def_named", []{
317 auto m = py::module_::import(
"pybind11_tests");
320 m.def(
"bad_arg_def_unnamed", []{
321 auto m = py::module_::import(
"pybind11_tests");
328 py::class_<NoneTester, std::shared_ptr<NoneTester>>(
m,
"NoneTester")
330 m.def(
"no_none1", &
none1, py::arg{}.none(
false));
331 m.def(
"no_none2", &
none2, py::arg{}.none(
false));
332 m.def(
"no_none3", &
none3, py::arg{}.none(
false));
333 m.def(
"no_none4", &
none4, py::arg{}.none(
false));
334 m.def(
"no_none5", &
none5, py::arg{}.none(
false));
335 m.def(
"ok_none1", &
none1);
336 m.def(
"ok_none2", &
none2, py::arg{}.none(
true));
337 m.def(
"ok_none3", &
none3);
338 m.def(
"ok_none4", &
none4, py::arg{}.none(
true));
339 m.def(
"ok_none5", &
none5);
341 m.def(
"no_none_kwarg", &
none2,
"a"_a.none(
false));
342 m.def(
"no_none_kwarg_kw_only", &
none2, py::kw_only(),
"a"_a.none(
false));
346 py::class_<StrIssue>(
m,
"StrIssue")
347 .def(py::init<int>())
349 .def(
"__str__", [](
const StrIssue &si) {
350 return "StrIssue[" + std::to_string(si.
val) +
"]"; }
359 py::class_<RegisteredDerived>(
m,
"RegisteredDerived")
378 py::class_<RefQualified>(
m,
"RefQualified")