mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-29 08:32:02 +00:00
New test_class_sh_property_bakein.py
Use cases in the wild: * `test_readonly_char6_member()`:4410c44ae6/torch/csrc/cuda/Module.cpp (L961)
* `test_readonly_const_char_ptr_member()`:862a439a84/include/permonst.h (L43)
This commit is contained in:
parent
2600bb67c5
commit
3406be6877
@ -1636,7 +1636,7 @@ struct property_cpp_function<
|
|||||||
D,
|
D,
|
||||||
detail::enable_if_t<
|
detail::enable_if_t<
|
||||||
detail::all_of<std::is_base_of<detail::type_caster_base<T>, detail::type_caster<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>> {
|
std::is_pointer<D>>::value>> {
|
||||||
|
|
||||||
using drp = typename std::remove_pointer<D>::type;
|
using drp = typename std::remove_pointer<D>::type;
|
||||||
@ -1686,6 +1686,7 @@ struct property_cpp_function<
|
|||||||
detail::all_of<std::is_base_of<detail::type_caster_base<T>, detail::type_caster<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::type_caster<D>>,
|
||||||
detail::none_of<std::is_pointer<D>,
|
detail::none_of<std::is_pointer<D>,
|
||||||
|
std::is_array<D>,
|
||||||
detail::is_instantiation<std::unique_ptr, D>,
|
detail::is_instantiation<std::unique_ptr, D>,
|
||||||
detail::is_instantiation<std::shared_ptr, D>>>::value>> {
|
detail::is_instantiation<std::shared_ptr, D>>>::value>> {
|
||||||
|
|
||||||
|
@ -127,6 +127,7 @@ set(PYBIND11_TEST_FILES
|
|||||||
test_class_sh_mi_thunks
|
test_class_sh_mi_thunks
|
||||||
test_class_sh_module_local.py
|
test_class_sh_module_local.py
|
||||||
test_class_sh_property
|
test_class_sh_property
|
||||||
|
test_class_sh_property_bakein
|
||||||
test_class_sh_property_non_owning
|
test_class_sh_property_non_owning
|
||||||
test_class_sh_shared_ptr_copy_move
|
test_class_sh_shared_ptr_copy_move
|
||||||
test_class_sh_trampoline_basic
|
test_class_sh_trampoline_basic
|
||||||
|
26
tests/test_class_sh_property_bakein.cpp
Normal file
26
tests/test_class_sh_property_bakein.cpp
Normal file
@ -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
tests/test_class_sh_property_bakein.py
Normal file
13
tests/test_class_sh_property_bakein.py
Normal file
@ -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*"
|
Loading…
Reference in New Issue
Block a user