File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -47,9 +47,15 @@ test_initializer enums([](py::module &m) {
4747 py::enum_<UnscopedEnum>(m, " UnscopedEnum" , py::arithmetic ())
4848 .value (" EOne" , EOne)
4949 .value (" ETwo" , ETwo)
50- .export_values ();
50+ .export_values ()
51+ .into_class ()
52+ .def (" x" , [](const UnscopedEnum& e) { return static_cast <int >(e) + 1 ; })
53+ .def_property_readonly (" y" , [](const UnscopedEnum& e) { return static_cast <int >(e) + 2 ; })
54+ .def_static (" a" , []() { return 41 ; })
55+ .def_property_readonly_static (" b" , [](py::object /* unused */ ) { return 42 ; });
5156
52- py::enum_<ScopedEnum>(m, " ScopedEnum" , py::arithmetic ())
57+ auto scoped_enum = py::enum_<ScopedEnum>(m, " ScopedEnum" , py::arithmetic ());
58+ scoped_enum
5359 .value (" Two" , ScopedEnum::Two)
5460 .value (" Three" , ScopedEnum::Three);
5561
Original file line number Diff line number Diff line change @@ -40,6 +40,14 @@ def test_unscoped_enum():
4040 assert not (2 < UnscopedEnum .EOne )
4141
4242
43+ def test_extra_defs ():
44+ from pybind11_tests import UnscopedEnum
45+ assert UnscopedEnum .EOne .x () == 2 and UnscopedEnum .ETwo .x () == 3
46+ assert UnscopedEnum .EOne .y == 3 and UnscopedEnum .ETwo .y == 4
47+ assert UnscopedEnum .a () == 41
48+ assert UnscopedEnum .b == 42
49+
50+
4351def test_scoped_enum ():
4452 from pybind11_tests import ScopedEnum , test_scoped_enum
4553
You can’t perform that action at this time.
0 commit comments