File tree Expand file tree Collapse file tree 3 files changed +12
-1
lines changed Expand file tree Collapse file tree 3 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -1274,6 +1274,10 @@ template <typename Type> class enum_ {
12741274 return cls;
12751275 }
12761276
1277+ operator handle () & {
1278+ return cls;
1279+ }
1280+
12771281private:
12781282 class_<Type> cls;
12791283 dict m_entries;
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ std::string test_scoped_enum(ScopedEnum z) {
4444test_initializer enums ([](py::module &m) {
4545 m.def (" test_scoped_enum" , &test_scoped_enum);
4646
47- py::enum_<UnscopedEnum>(m, " UnscopedEnum" , py::arithmetic ())
47+ auto e = py::enum_<UnscopedEnum>(m, " UnscopedEnum" , py::arithmetic ())
4848 .value (" EOne" , EOne)
4949 .value (" ETwo" , ETwo)
5050 .export_values ()
@@ -59,6 +59,8 @@ test_initializer enums([](py::module &m) {
5959 .value (" Two" , ScopedEnum::Two)
6060 .value (" Three" , ScopedEnum::Three);
6161
62+ py::setattr (e, " Alias" , scoped_enum);
63+
6264 py::enum_<Flags>(m, " Flags" , py::arithmetic ())
6365 .value (" Read" , Flags::Read)
6466 .value (" Write" , Flags::Write)
Original file line number Diff line number Diff line change @@ -40,6 +40,11 @@ def test_unscoped_enum():
4040 assert not (2 < UnscopedEnum .EOne )
4141
4242
43+ def test_enum_as_handle ():
44+ from pybind11_tests import UnscopedEnum , ScopedEnum
45+ assert UnscopedEnum .Alias is ScopedEnum
46+
47+
4348def test_extra_defs ():
4449 from pybind11_tests import UnscopedEnum
4550 assert UnscopedEnum .EOne .x () == 2 and UnscopedEnum .ETwo .x () == 3
You can’t perform that action at this time.
0 commit comments