Skip to content

Commit

Permalink
New test_class_sh_property_bakein.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Jul 14, 2024
1 parent 2600bb6 commit 3406be6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ struct property_cpp_function<
D,
detail::enable_if_t<
detail::all_of<std::is_base_of<detail::type_caster_base<T>, detail::type_caster<T>>,
std::is_base_of<detail::type_caster_base<D>, detail::type_caster<D>>,
std::is_base_of<detail::type_caster_base<D>, detail::make_caster<D>>,
std::is_pointer<D>>::value>> {

using drp = typename std::remove_pointer<D>::type;
Expand Down Expand Up @@ -1686,6 +1686,7 @@ struct property_cpp_function<
detail::all_of<std::is_base_of<detail::type_caster_base<T>, detail::type_caster<T>>,
std::is_base_of<detail::type_caster_base<D>, detail::type_caster<D>>,
detail::none_of<std::is_pointer<D>,
std::is_array<D>,
detail::is_instantiation<std::unique_ptr, D>,
detail::is_instantiation<std::shared_ptr, D>>>::value>> {

Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ set(PYBIND11_TEST_FILES
test_class_sh_mi_thunks
test_class_sh_module_local.py
test_class_sh_property
test_class_sh_property_bakein
test_class_sh_property_non_owning
test_class_sh_shared_ptr_copy_move
test_class_sh_trampoline_basic
Expand Down
26 changes: 26 additions & 0 deletions tests/test_class_sh_property_bakein.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "pybind11_tests.h"

namespace test_class_sh_property_bakein {

struct WithCharArrayMember {
WithCharArrayMember() { std::strcpy(char6_member, "Char6"); }
char char6_member[6];
};

struct WithConstCharPtrMember {
const char *const_char_ptr_member = "ConstChar*";
};

} // namespace test_class_sh_property_bakein

TEST_SUBMODULE(class_sh_property_bakein, m) {
using namespace test_class_sh_property_bakein;

py::class_<WithCharArrayMember>(m, "WithCharArrayMember")
.def(py::init<>())
.def_readonly("char6_member", &WithCharArrayMember::char6_member);

py::class_<WithConstCharPtrMember>(m, "WithConstCharPtrMember")
.def(py::init<>())
.def_readonly("const_char_ptr_member", &WithConstCharPtrMember::const_char_ptr_member);
}
13 changes: 13 additions & 0 deletions tests/test_class_sh_property_bakein.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from __future__ import annotations

from pybind11_tests import class_sh_property_bakein as m


def test_readonly_char6_member():
obj = m.WithCharArrayMember()
assert obj.char6_member == "Char6"


def test_readonly_const_char_ptr_member():
obj = m.WithConstCharPtrMember()
assert obj.const_char_ptr_member == "ConstChar*"

0 comments on commit 3406be6

Please sign in to comment.