From 260961b78da4e13868883b05a35b9bb9dfd307e7 Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Fri, 6 Sep 2024 13:31:25 +0100 Subject: [PATCH 1/4] Allow subclasses of args and kwargs The current implementation disallows subclasses of args and kwargs --- include/pybind11/cast.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 0c862e4be..e3c8b9f65 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -1570,9 +1570,9 @@ class argument_loader { using indices = make_index_sequence; template - using argument_is_args = std::is_same, args>; + using argument_is_args = std::is_base_of>; template - using argument_is_kwargs = std::is_same, kwargs>; + using argument_is_kwargs = std::is_base_of>; // Get kwargs argument position, or -1 if not present: static constexpr auto kwargs_pos = constexpr_last(); From 2bf09e21db4722eebee3aeb3d7dafd95279f8e37 Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Fri, 6 Sep 2024 13:36:51 +0100 Subject: [PATCH 2/4] Added object type hint to args and kwargs --- include/pybind11/cast.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index e3c8b9f65..1f28a3a92 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -1010,11 +1010,13 @@ struct handle_type_name { }; template <> struct handle_type_name { - static constexpr auto name = const_name("*args"); + static constexpr auto name = const_name("*args: ") + make_caster::name; +}; }; template <> struct handle_type_name { - static constexpr auto name = const_name("**kwargs"); + static constexpr auto name = const_name("**kwargs: ") + make_caster::name; +}; }; template <> struct handle_type_name { From 862b807adf06b2b1cbe555c1d044dde19d0a0dd2 Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Fri, 6 Sep 2024 13:40:10 +0100 Subject: [PATCH 3/4] Added type hinted args and kwargs classes --- include/pybind11/cast.h | 6 ++++++ include/pybind11/pytypes.h | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 1f28a3a92..99d0dd0ef 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -1012,11 +1012,17 @@ template <> struct handle_type_name { static constexpr auto name = const_name("*args: ") + make_caster::name; }; +template +struct handle_type_name> { + static constexpr auto name = const_name("*args: ") + make_caster::name; }; template <> struct handle_type_name { static constexpr auto name = const_name("**kwargs: ") + make_caster::name; }; +template +struct handle_type_name> { + static constexpr auto name = const_name("**kwargs: ") + make_caster::name; }; template <> struct handle_type_name { diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 1e76d7bc1..4b9b0f579 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -2216,6 +2216,16 @@ class kwargs : public dict { PYBIND11_OBJECT_DEFAULT(kwargs, dict, PyDict_Check) }; +template +class Args : public args { + using args::args; +}; + +template +class KWArgs : public kwargs { + using kwargs::kwargs; +}; + class anyset : public object { public: PYBIND11_OBJECT(anyset, object, PyAnySet_Check) From 14dbbce6bd3e2a49324792f6ecf96e0f0a08f25c Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Fri, 6 Sep 2024 14:07:26 +0100 Subject: [PATCH 4/4] Changed default type hint to typing.Any --- include/pybind11/cast.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 99d0dd0ef..d8d7dcb4f 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -1010,7 +1010,7 @@ struct handle_type_name { }; template <> struct handle_type_name { - static constexpr auto name = const_name("*args: ") + make_caster::name; + static constexpr auto name = const_name("*args: typing.Any"); }; template struct handle_type_name> { @@ -1018,7 +1018,7 @@ struct handle_type_name> { }; template <> struct handle_type_name { - static constexpr auto name = const_name("**kwargs: ") + make_caster::name; + static constexpr auto name = const_name("**kwargs: typing.Any"); }; template struct handle_type_name> {