19 = [](
int x,
int y) {
return "x=" + std::to_string(x) +
", y=" + std::to_string(
y); };
22 m.def(
"kw_func0", kw_func);
26 "kw_func3", [](
const char *) {},
py::arg(
"data") = std::string(
"Hello world!"));
29 std::vector<int> list{{13, 17}};
32 [](
const std::vector<int> &entries) {
33 std::string
ret =
"{";
34 for (
int i : entries) {
35 ret += std::to_string(
i) +
" ";
42 m.def(
"kw_func_udl", kw_func,
"x"_a,
"y"_a = 300);
43 m.def(
"kw_func_udl_z", kw_func,
"x"_a,
"y"_a = 0);
46 m.def(
"args_function", [](
py::args args) -> py::tuple {
return std::move(args); });
47 m.def(
"args_kwargs_function", [](
const py::args &args,
const py::kwargs &
kwargs) {
52 m.def(
"mixed_plus_args",
54 m.def(
"mixed_plus_kwargs",
55 [](
int i,
double j,
const py::kwargs &kwargs) {
return py::make_tuple(i, j, kwargs); });
56 auto mixed_plus_both = [](
int i,
double j,
const py::args &
args,
const py::kwargs &kwargs) {
59 m.def(
"mixed_plus_args_kwargs", mixed_plus_both);
61 m.def(
"mixed_plus_args_kwargs_defaults",
74 [](
int i,
double j,
const py::args &args,
int z,
const py::kwargs &kwargs) {
82 "args_kwonly_kwargs_defaults",
83 [](
int i,
double j,
const py::args &args,
int z,
const py::kwargs &kwargs) {
90 "args_kwonly_full_monty",
91 [](
int h,
int i,
double j,
const py::args &args,
int z,
const py::kwargs &kwargs) {
103 # define GC_IF_NEEDED ConstructorStats::gc() 105 # define GC_IF_NEEDED 107 m.def(
"arg_refcount_h", [](py::handle h) {
109 return h.ref_count();
111 m.def(
"arg_refcount_h", [](py::handle h, py::handle, py::handle) {
113 return h.ref_count();
115 m.def(
"arg_refcount_o", [](
const py::object &o) {
117 return o.ref_count();
121 py::tuple
t(a.size());
122 for (
size_t i = 0; i < a.size(); i++) {
128 m.def(
"mixed_args_refcount", [](
const py::object &o,
py::args a) {
130 py::tuple
t(a.size() + 1);
131 t[0] = o.ref_count();
132 for (
size_t i = 0; i < a.size(); i++) {
134 t[i + 1] = (
int) Py_REFCNT(PyTuple_GET_ITEM(a.ptr(),
static_cast<py::ssize_t>(
i)));
164 "kw_only_with_defaults",
165 [](
int i,
int j,
int k,
int z) {
return py::make_tuple(i, j, k, z); },
179 [](
int i,
int j,
int k,
const py::kwargs &kwargs) {
187 m.def(
"register_invalid_kw_only", [](py::module_
m) {
226 #ifdef PYBIND11_NEVER_DEFINED_EVER 229 "bad_kw_only1", [](
int) {}, py::kw_only());
232 "bad_kw_only2", [](
int i,
py::args) {}, py::kw_only(),
"i"_a);
237 void foo(
int,
float) {}
239 py::class_<KWClass>(
m,
"KWClass")
246 "class_default_argument",
247 [](py::object a) {
return py::repr(std::move(a)); },
248 "a"_a = py::module_::import(
"decimal").attr(
"Decimal"));
254 struct first_arg_kw_only {};
255 py::class_<first_arg_kw_only>(
m,
"first_arg_kw_only")
256 .def(
py::init([](
int) {
return first_arg_kw_only(); }),
261 [](first_arg_kw_only &,
int,
int) {},
269 [](first_arg_kw_only &,
int,
int) {},
void foo(CV_QUALIFIER Matrix3d &m)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
TEST_SUBMODULE(kwargs_and_defaults, m)
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
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