Skip to content

Commit af056b6

Browse files
authored
fix: __index__ on Enum should always be present. (#3700)
* chore: minor odd py version cleanup * Update include/pybind11/pybind11.h * fix: always make __index__ available
1 parent 1b84188 commit af056b6

File tree

2 files changed

+1
-7
lines changed

2 files changed

+1
-7
lines changed

include/pybind11/detail/common.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,6 @@
153153

154154
/// Include Python header, disable linking to pythonX_d.lib on Windows in debug mode
155155
#if defined(_MSC_VER)
156-
# if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 4)
157-
# define HAVE_ROUND 1
158-
# endif
159156
# pragma warning(push)
160157
// C4505: 'PySlice_GetIndicesEx': unreferenced local function has been removed (PyPy only)
161158
# pragma warning(disable: 4505)

include/pybind11/pybind11.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,13 +1911,10 @@ template <typename Type> class enum_ : public class_<Type> {
19111911
def(init([](Scalar i) { return static_cast<Type>(i); }), arg("value"));
19121912
def_property_readonly("value", [](Type value) { return (Scalar) value; });
19131913
def("__int__", [](Type value) { return (Scalar) value; });
1914+
def("__index__", [](Type value) { return (Scalar) value; });
19141915
#if PY_MAJOR_VERSION < 3
19151916
def("__long__", [](Type value) { return (Scalar) value; });
19161917
#endif
1917-
#if PY_MAJOR_VERSION > 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8)
1918-
def("__index__", [](Type value) { return (Scalar) value; });
1919-
#endif
1920-
19211918
attr("__setstate__") = cpp_function(
19221919
[](detail::value_and_holder &v_h, Scalar arg) {
19231920
detail::initimpl::setstate<Base>(v_h, static_cast<Type>(arg),

0 commit comments

Comments
 (0)