mirror of https://github.com/pybind/pybind11.git
Compare commits
9 Commits
83fc959bf8
...
17f97901bf
Author | SHA1 | Date |
---|---|---|
gentlegiantJGC | 17f97901bf | |
pre-commit-ci[bot] | b74f295c9d | |
gentlegiantJGC | 19503bfd31 | |
gentlegiantJGC | 97c6798f72 | |
gentlegiantJGC | 4f54b374fb | |
pre-commit-ci[bot] | ce5e7be7f8 | |
gentlegiantJGC | 4aaf8bb35f | |
pre-commit-ci[bot] | 82c99336ca | |
gentlegiantJGC | 82906b97c1 |
|
@ -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