Compare commits

...

6 Commits

Author SHA1 Message Date
gentlegiantJGC 7775595943
Merge 14dbbce6bd into 1f8b4a7f1a 2024-09-20 11:18:09 +01:00
Hintay 1f8b4a7f1a
fix(cmake): `NO_EXTRAS` in `pybind11_add_module` function partially working (#5378) 2024-09-19 11:24:35 -04:00
gentlegiantJGC 14dbbce6bd Changed default type hint to typing.Any 2024-09-06 14:07:26 +01:00
gentlegiantJGC 862b807adf Added type hinted args and kwargs classes 2024-09-06 13:40:10 +01:00
gentlegiantJGC 2bf09e21db Added object type hint to args and kwargs 2024-09-06 13:36:51 +01:00
gentlegiantJGC 260961b78d Allow subclasses of args and kwargs
The current implementation disallows subclasses of args and kwargs
2024-09-06 13:31:25 +01:00
3 changed files with 22 additions and 8 deletions

View File

@ -1010,11 +1010,19 @@ struct handle_type_name<weakref> {
};
template <>
struct handle_type_name<args> {
static constexpr auto name = const_name("*args");
static constexpr auto name = const_name("*args: typing.Any");
};
template <typename T>
struct handle_type_name<Args<T>> {
static constexpr auto name = const_name("*args: ") + make_caster<T>::name;
};
template <>
struct handle_type_name<kwargs> {
static constexpr auto name = const_name("**kwargs");
static constexpr auto name = const_name("**kwargs: typing.Any");
};
template <typename T>
struct handle_type_name<KWArgs<T>> {
static constexpr auto name = const_name("**kwargs: ") + make_caster<T>::name;
};
template <>
struct handle_type_name<obj_attr_accessor> {
@ -1570,9 +1578,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...>();

View File

@ -2216,6 +2216,16 @@ class kwargs : public dict {
PYBIND11_OBJECT_DEFAULT(kwargs, dict, PyDict_Check)
};
template <typename T>
class Args : public args {
using args::args;
};
template <typename T>
class KWArgs : public kwargs {
using kwargs::kwargs;
};
class anyset : public object {
public:
PYBIND11_OBJECT(anyset, object, PyAnySet_Check)

View File

@ -274,10 +274,6 @@ function(pybind11_add_module target_name)
target_link_libraries(${target_name} PRIVATE pybind11::embed)
endif()
if(MSVC)
target_link_libraries(${target_name} PRIVATE pybind11::windows_extras)
endif()
# -fvisibility=hidden is required to allow multiple modules compiled against
# different pybind versions to work properly, and for some features (e.g.
# py::module_local). We force it on everything inside the `pybind11`