Compare commits

...

8 Commits

Author SHA1 Message Date
pre-commit-ci[bot] b74f295c9d style: pre-commit fixes 2024-09-20 19:22:08 +00:00
gentlegiantJGC 19503bfd31 Added namespaces 2024-09-20 20:21:46 +01:00
gentlegiantJGC 97c6798f72 Moved classes outside of function 2024-09-20 20:17:28 +01:00
gentlegiantJGC 4f54b374fb Added handle_type_name 2024-09-20 20:10:49 +01:00
pre-commit-ci[bot] ce5e7be7f8 style: pre-commit fixes 2024-09-20 18:25:10 +00:00
gentlegiantJGC 4aaf8bb35f Added missing semi-colons 2024-09-20 19:24:38 +01:00
pre-commit-ci[bot] 82c99336ca style: pre-commit fixes 2024-09-20 17:58:16 +00:00
gentlegiantJGC 82906b97c1 Added test case 2024-09-20 18:57:50 +01:00
2 changed files with 31 additions and 0 deletions

View File

@ -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);
});
}

View File

@ -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},
)