Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class type_caster_enum_type {
parent);
}

template <typename SrcType>
static handle cast(SrcType *src, return_value_policy policy, handle parent) {
return cast(*src, policy, parent);
}

bool load(handle src, bool convert) {
handle native_enum
= global_internals_native_enum_type_map_get_item(std::type_index(typeid(EnumType)));
Expand Down
9 changes: 9 additions & 0 deletions tests/test_native_enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ TEST_SUBMODULE(native_enum, m) {
m.def("pass_color", [](color e) { return static_cast<int>(e); });
m.def("return_color", [](int i) { return static_cast<color>(i); });

m.def("return_color_const_ptr", []() -> const color * {
static const color test_color = color::red;
return &test_color;
});
m.def("return_color_mutbl_ptr", []() -> color * {
static color test_color = color::green;
return &test_color;
});

py::native_enum<func_sig_rendering>(m, "func_sig_rendering", "enum.Enum").finalize();
m.def(
"pass_and_return_func_sig_rendering",
Expand Down
5 changes: 5 additions & 0 deletions tests/test_native_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ def test_return_color_fail():
assert str(excinfo_cast.value) == str(excinfo_direct.value)


def test_return_color_ptr():
assert m.return_color_const_ptr() == m.color.red
assert m.return_color_mutbl_ptr() == m.color.green


def test_property_type_hint():
prop = m.class_with_enum.__dict__["nested_value"]
assert isinstance(prop, property)
Expand Down
Loading