15 auto kw_func = [](
int x,
int y) {
return "x=" + std::to_string(x) +
", y=" + std::to_string(
y); };
18 m.def(
"kw_func0", kw_func);
21 m.def(
"kw_func3", [](
const char *) { },
py::arg(
"data") = std::string(
"Hello world!"));
24 std::vector<int> list{{13, 17}};
25 m.def(
"kw_func4", [](
const std::vector<int> &entries) {
26 std::string
ret =
"{";
28 ret += std::to_string(
i) +
" ";
33 m.def(
"kw_func_udl", kw_func,
"x"_a,
"y"_a=300);
34 m.def(
"kw_func_udl_z", kw_func,
"x"_a,
"y"_a=0);
38 return std::move(args);
45 m.def(
"mixed_plus_args", [](
int i,
double j,
py::args args) {
48 m.def(
"mixed_plus_kwargs", [](
int i,
double j, py::kwargs kwargs) {
51 auto mixed_plus_both = [](
int i,
double j,
py::args args, py::kwargs kwargs) {
54 m.def(
"mixed_plus_args_kwargs", mixed_plus_both);
56 m.def(
"mixed_plus_args_kwargs_defaults", mixed_plus_both,
62 #define GC_IF_NEEDED ConstructorStats::gc() 66 m.def(
"arg_refcount_h", [](py::handle
h) {
GC_IF_NEEDED;
return h.ref_count(); });
67 m.def(
"arg_refcount_h", [](py::handle h, py::handle, py::handle) {
GC_IF_NEEDED;
return h.ref_count(); });
68 m.def(
"arg_refcount_o", [](py::object o) {
GC_IF_NEEDED;
return o.ref_count(); });
71 py::tuple
t(a.size());
72 for (
size_t i = 0; i < a.size(); i++)
74 t[i] = (
int) Py_REFCNT(PyTuple_GET_ITEM(a.ptr(),
static_cast<ssize_t>(
i)));
77 m.def(
"mixed_args_refcount", [](py::object o,
py::args a) {
79 py::tuple
t(a.size() + 1);
81 for (
size_t i = 0; i < a.size(); i++)
83 t[i + 1] = (
int) Py_REFCNT(PyTuple_GET_ITEM(a.ptr(),
static_cast<ssize_t>(
i)));
100 m.def(
"kw_only_some", [](
int i,
int j,
int k) {
return py::make_tuple(i, j, k); },
102 m.def(
"kw_only_with_defaults", [](
int i,
int j,
int k,
int z) {
return py::make_tuple(i, j, k, z); },
103 py::arg() = 3,
"j"_a = 4, py::kw_only(),
"k"_a = 5,
"z"_a);
104 m.def(
"kw_only_mixed", [](
int i,
int j) {
return py::make_tuple(i, j); },
105 "i"_a, py::kw_only(),
"j"_a);
106 m.def(
"kw_only_plus_more", [](
int i,
int j,
int k, py::kwargs kwargs) {
111 m.def(
"bad_kw_only", [](
int i,
int j) {
return py::make_tuple(i, j); },
112 py::kw_only(),
py::arg() ,
"j"_a);
116 m.def(
"pos_only_all", [](
int i,
int j) {
return py::make_tuple(i, j); },
118 m.def(
"pos_only_mix", [](
int i,
int j) {
return py::make_tuple(i, j); },
120 m.def(
"pos_kw_only_mix", [](
int i,
int j,
int k) {
return py::make_tuple(i, j, k); },
122 m.def(
"pos_only_def_mix", [](
int i,
int j,
int k) {
return py::make_tuple(i, j, k); },
133 struct KWClass {
void foo(
int,
float) {} };
134 py::class_<KWClass>(
m,
"KWClass")
140 m.def(
"class_default_argument", [](py::object a) {
return py::repr(a); },
141 "a"_a = py::module::import(
"decimal").attr(
"Decimal"));
void foo(CV_QUALIFIER Matrix3d &m)
Tuple< Args... > make_tuple(Args...args)
Creates a tuple object, deducing the target type from the types of arguments.
TEST_SUBMODULE(kwargs_and_defaults, m)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x