You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
static_assert(has_arg_annotations || !has_kwonly_args, "py::kwonly requires the use of argument annotations");
194
-
static_assert(!(has_args && has_kwonly_args), "py::kwonly cannot be combined with a py::args argument");
194
+
static_assert(has_arg_annotations || !has_kw_only_args, "py::kw_only requires the use of argument annotations");
195
+
static_assert(has_arg_annotations || !has_pos_only_args, "py::pos_only requires the use of argument annotations (for docstrings and aligning the annotations to the argument)");
196
+
static_assert(!(has_args && has_kw_only_args), "py::kw_only cannot be combined with a py::args argument");
195
197
}
196
198
197
199
/* Generate a readable signature describing the function's arguments and return value types */
@@ -257,7 +259,10 @@ class cpp_function : public function {
257
259
// Write arg name for everything except *args and **kwargs.
258
260
if (*(pc + 1) == '*')
259
261
continue;
260
-
262
+
// Separator for keyword-only arguments, placed before the kw
263
+
// arguments start
264
+
if (rec->nargs_kw_only > 0 && arg_index + rec->nargs_kw_only == args)
265
+
signature += "*, ";
261
266
if (arg_index < rec->args.size() && rec->args[arg_index].name) {
262
267
signature += rec->args[arg_index].name;
263
268
} elseif (arg_index == 0 && rec->is_method) {
@@ -272,6 +277,10 @@ class cpp_function : public function {
272
277
signature += " = ";
273
278
signature += rec->args[arg_index].descr;
274
279
}
280
+
// Separator for positional-only arguments (placed after the
281
+
// argument, rather than before like *
282
+
if (rec->nargs_pos_only > 0 && (arg_index + 1) == rec->nargs_pos_only)
283
+
signature += ", /";
275
284
arg_index++;
276
285
} elseif (c == '%') {
277
286
const std::type_info *t = types[type_index++];
@@ -297,6 +306,7 @@ class cpp_function : public function {
297
306
signature += c;
298
307
}
299
308
}
309
+
300
310
if (arg_index != args || types[type_index] != nullptr)
301
311
pybind11_fail("Internal error while parsing type signature (2)");
302
312
@@ -512,7 +522,7 @@ class cpp_function : public function {
512
522
size_t num_args = func.nargs; // Number of positional arguments that we need
513
523
if (func.has_args) --num_args; // (but don't count py::args
514
524
if (func.has_kwargs) --num_args; // or py::kwargs)
515
-
size_t pos_args = num_args - func.nargs_kwonly;
525
+
size_t pos_args = num_args - func.nargs_kw_only;
516
526
517
527
if (!func.has_args && n_args_in > pos_args)
518
528
continue; // Too many positional arguments for this overload
@@ -561,6 +571,26 @@ class cpp_function : public function {
561
571
// We'll need to copy this if we steal some kwargs for defaults
0 commit comments