mirror of https://github.com/pybind/pybind11.git
Merge b74f295c9d
into 1f8b4a7f1a
This commit is contained in:
commit
17f97901bf
|
@ -1570,9 +1570,9 @@ class argument_loader {
|
|||
using indices = make_index_sequence<sizeof...(Args)>;
|
||||
|
||||
template <typename Arg>
|
||||
using argument_is_args = std::is_same<intrinsic_t<Arg>, args>;
|
||||
using argument_is_args = std::is_base_of<args, intrinsic_t<Arg>>;
|
||||
template <typename Arg>
|
||||
using argument_is_kwargs = std::is_same<intrinsic_t<Arg>, kwargs>;
|
||||
using argument_is_kwargs = std::is_base_of<kwargs, intrinsic_t<Arg>>;
|
||||
// Get kwargs argument position, or -1 if not present:
|
||||
static constexpr auto kwargs_pos = constexpr_last<argument_is_kwargs, Args...>();
|
||||
|
||||
|
|
|
@ -14,6 +14,26 @@
|
|||
|
||||
#include <utility>
|
||||
|
||||
// Classes needed for subclass test.
|
||||
class ArgsSubclass : public py::args {
|
||||
using py::args::args;
|
||||
};
|
||||
class KWArgsSubclass : public py::kwargs {
|
||||
using py::kwargs::kwargs;
|
||||
};
|
||||
namespace pybind11 {
|
||||
namespace detail {
|
||||
template <>
|
||||
struct handle_type_name<ArgsSubclass> {
|
||||
static constexpr auto name = const_name("*args");
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<KWArgsSubclass> {
|
||||
static constexpr auto name = const_name("**kwargs");
|
||||
};
|
||||
} // namespace detail
|
||||
} // namespace pybind11
|
||||
|
||||
TEST_SUBMODULE(kwargs_and_defaults, m) {
|
||||
auto kw_func
|
||||
= [](int x, int y) { return "x=" + std::to_string(x) + ", y=" + std::to_string(y); };
|
||||
|
@ -322,4 +342,10 @@ TEST_SUBMODULE(kwargs_and_defaults, m) {
|
|||
py::pos_only{},
|
||||
py::arg("i"),
|
||||
py::arg("j"));
|
||||
|
||||
// Test support for args and kwargs subclasses
|
||||
m.def("args_kwargs_subclass_function",
|
||||
[](const ArgsSubclass &args, const KWArgsSubclass &kwargs) {
|
||||
return py::make_tuple(args, kwargs);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -426,3 +426,8 @@ def test_args_refcount():
|
|||
assert m.mixed_args_refcount(myval, myval, myval) == (exp3_3, exp3_3, exp3_3)
|
||||
|
||||
assert m.class_default_argument() == "<class 'decimal.Decimal'>"
|
||||
|
||||
assert m.args_kwargs_subclass_function(7, 8, myval, a=1, b=myval) == (
|
||||
(7, 8, myval),
|
||||
{"a": 1, "b": myval},
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue