19 = [](
int x,
int y) {
return "x=" + std::to_string(
x) +
", y=" + std::to_string(
y); };
22 m.def(
"kw_func0", kw_func);
25 m.def(
"kw_func3", [](
const char *) {},
py::arg(
"data") = std::string(
"Hello world!"));
28 std::vector<int> list{{13, 17}};
31 [](
const std::vector<int> &entries) {
32 std::string
ret =
"{";
33 for (
int i : entries) {
34 ret += std::to_string(
i) +
" ";
41 m.def(
"kw_func_udl", kw_func,
"x"_a,
"y"_a = 300);
42 m.def(
"kw_func_udl_z", kw_func,
"x"_a,
"y"_a = 0);
46 std::string repr_string;
48 explicit CustomRepr(
const std::string &
repr) : repr_string(
repr) {}
50 std::string
__repr__()
const {
return repr_string; }
53 py::class_<CustomRepr>(
m,
"CustomRepr")
54 .def(py::init<const std::string &>())
59 [](
const CustomRepr &) {},
60 py::arg(
"custom") = CustomRepr(
" array([[A, B], [C, D]]) "));
63 [](
const CustomRepr &) {},
64 py::arg(
"custom") = CustomRepr(
" array([[A, B],\n[C, D]]) "));
67 [](
const CustomRepr &) {},
68 py::arg(
"custom") = CustomRepr(
"\v\n array([[A, B], [C, D]])"));
71 [](
const CustomRepr &) {},
72 py::arg(
"custom") = CustomRepr(
"array([[A, B], [C, D]]) \f\n"));
75 [](
const CustomRepr &) {},
76 py::arg(
"custom") = CustomRepr(
"array([[A, B],\n\f\n[C, D]])"));
79 [](
const CustomRepr &) {},
80 py::arg(
"custom") = CustomRepr(
"array([[A, B],\r [C, D]])"));
81 m.def(
"kw_lb_func6", [](
const CustomRepr &) {},
py::arg(
"custom") = CustomRepr(
" \v\t "));
84 [](
const std::string &) {},
85 py::arg(
"str_arg") =
"First line.\n Second line.");
86 m.def(
"kw_lb_func8", [](
const CustomRepr &) {},
py::arg(
"custom") = CustomRepr(
""));
92 #ifdef PYBIND11_DETECTED_CLANG_WITH_MISLEADING_CALL_STD_MOVE_EXPLICITLY_WARNING
103 m.def(
"mixed_plus_args",
105 m.def(
"mixed_plus_kwargs",
110 m.def(
"mixed_plus_args_kwargs", mixed_plus_both);
112 m.def(
"mixed_plus_args_kwargs_defaults",
124 "args_kwonly_kwargs",
133 "args_kwonly_kwargs_defaults",
141 "args_kwonly_full_monty",
155 # define GC_IF_NEEDED ConstructorStats::gc()
156 # define REFCNT(x) (int) Py_REFCNT(x)
158 # define GC_IF_NEEDED
159 # define REFCNT(x) Py_REFCNT(x)
161 m.def(
"arg_refcount_h", [](py::handle
h) {
163 return h.ref_count();
165 m.def(
"arg_refcount_h", [](py::handle
h, py::handle, py::handle) {
167 return h.ref_count();
169 m.def(
"arg_refcount_o", [](
const py::object &o) {
171 return o.ref_count();
175 py::tuple
t(
a.size());
176 for (
size_t i = 0;
i <
a.size();
i++) {
182 m.def(
"mixed_args_refcount", [](
const py::object &o,
py::args a) {
184 py::tuple
t(
a.size() + 1);
185 t[0] = o.ref_count();
186 for (
size_t i = 0;
i <
a.size();
i++) {
218 "kw_only_with_defaults",
233 [](
int i,
int j,
int k,
const py::kwargs &
kwargs) {
241 m.def(
"register_invalid_kw_only", [](py::module_
m) {
280 #ifdef PYBIND11_NEVER_DEFINED_EVER
282 m.def(
"bad_kw_only1", [](
int) {}, py::kw_only());
284 m.def(
"bad_kw_only2", [](
int i,
py::args) {}, py::kw_only(),
"i"_a);
289 void foo(
int,
float) {}
291 py::class_<KWClass>(
m,
"KWClass")
298 "class_default_argument",
299 [](py::object
a) {
return py::repr(std::move(
a)); },
300 "a"_a = py::module_::import(
"decimal").attr(
"Decimal"));
306 struct first_arg_kw_only {};
307 py::class_<first_arg_kw_only>(
m,
"first_arg_kw_only")
308 .def(
py::init([](
int) {
return first_arg_kw_only(); }),
313 [](first_arg_kw_only &,
int,
int) {},
321 [](first_arg_kw_only &,
int,
int) {},