Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address regression introduced in #5381 #5396

Merged
merged 21 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8cf1cdb
Incomplete attempt to address regression introduced in #5381
francesco-ballarin Oct 5, 2024
9d107d2
style: pre-commit fixes
pre-commit-ci[bot] Oct 5, 2024
b508a07
Revert "style: pre-commit fixes"
francesco-ballarin Oct 6, 2024
95e0325
Revert "Incomplete attempt to address regression introduced in #5381"
francesco-ballarin Oct 6, 2024
8cbca65
Simpler fix for the regression introduced in #5381
francesco-ballarin Oct 6, 2024
4c87a23
style: pre-commit fixes
pre-commit-ci[bot] Oct 6, 2024
b375ad7
Added if constexpr workaround
gentlegiantJGC Oct 10, 2024
56758c7
style: pre-commit fixes
pre-commit-ci[bot] Oct 10, 2024
e55e864
Replace if constexpr with template struct
gentlegiantJGC Oct 10, 2024
badb28d
style: pre-commit fixes
pre-commit-ci[bot] Oct 10, 2024
6494448
Made comment clearer
gentlegiantJGC Oct 10, 2024
84cd376
Added test cases
gentlegiantJGC Oct 12, 2024
1c845cf
style: pre-commit fixes
pre-commit-ci[bot] Oct 12, 2024
5965a65
Fixed is_same_or_base_of reference
gentlegiantJGC Oct 12, 2024
add8277
style: pre-commit fixes
pre-commit-ci[bot] Oct 12, 2024
c4ce357
Added static assert messages
gentlegiantJGC Oct 12, 2024
8b9e5d1
style: pre-commit fixes
pre-commit-ci[bot] Oct 12, 2024
ccb165b
Replaced typedef with using
gentlegiantJGC Oct 12, 2024
8bc767d
style: pre-commit fixes
pre-commit-ci[bot] Oct 12, 2024
b7c4fe9
Back out `ForwardClassPtr` (to be discussed separately). Tested local…
rwgk Oct 12, 2024
b778cc6
Shuffle new `static_assert()` and leave error messages blank (they ar…
rwgk Oct 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1564,15 +1564,24 @@ struct function_call {
handle init_self;
};

// See PR #5396 for the discussion that led to this
template <typename Base, typename Derived, typename = void>
struct is_same_or_base_of : std::is_same<Base, Derived> {};

// Only evaluate is_base_of if Derived is complete.
// is_base_of raises a compiler error if Derived is incomplete.
template <typename Base, typename Derived>
struct is_same_or_base_of<Base, Derived, decltype(void(sizeof(Derived)))>
: any_of<std::is_same<Base, Derived>, std::is_base_of<Base, Derived>> {};

/// Helper class which loads arguments for C++ functions called from Python
template <typename... Args>
class argument_loader {
using indices = make_index_sequence<sizeof...(Args)>;

template <typename Arg>
using argument_is_args = std::is_base_of<args, intrinsic_t<Arg>>;
using argument_is_args = is_same_or_base_of<args, intrinsic_t<Arg>>;
template <typename Arg>
using argument_is_kwargs = std::is_base_of<kwargs, intrinsic_t<Arg>>;
using argument_is_kwargs = is_same_or_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...>();

Expand Down
16 changes: 16 additions & 0 deletions tests/test_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,24 @@ void bind_empty0(py::module_ &m) {
}

} // namespace pr4220_tripped_over_this

namespace pr5396_forward_declared_class {
class ForwardClass;
class Args : public py::args {};
} // namespace pr5396_forward_declared_class

} // namespace test_class

static_assert(py::detail::is_same_or_base_of<py::args, py::args>::value, "");
static_assert(
py::detail::is_same_or_base_of<py::args,
test_class::pr5396_forward_declared_class::Args>::value,
"");
static_assert(!py::detail::is_same_or_base_of<
py::args,
test_class::pr5396_forward_declared_class::ForwardClass>::value,
"");

TEST_SUBMODULE(class_, m) {
m.def("obj_class_name", [](py::handle obj) { return py::detail::obj_class_name(obj.ptr()); });

Expand Down