From af056b65d3312d2fb19b2900741413a7b06b9de2 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 8 Feb 2022 11:47:30 -0500 Subject: [PATCH] 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 --- include/pybind11/detail/common.h | 3 --- include/pybind11/pybind11.h | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index d9f838236..14788b652 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -153,9 +153,6 @@ /// Include Python header, disable linking to pythonX_d.lib on Windows in debug mode #if defined(_MSC_VER) -# if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 4) -# define HAVE_ROUND 1 -# endif # pragma warning(push) // C4505: 'PySlice_GetIndicesEx': unreferenced local function has been removed (PyPy only) # pragma warning(disable: 4505) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 7aa93bb5a..7dcea95b4 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1911,13 +1911,10 @@ public: def(init([](Scalar i) { return static_cast(i); }), arg("value")); def_property_readonly("value", [](Type value) { return (Scalar) value; }); def("__int__", [](Type value) { return (Scalar) value; }); + def("__index__", [](Type value) { return (Scalar) value; }); #if PY_MAJOR_VERSION < 3 def("__long__", [](Type value) { return (Scalar) value; }); #endif - #if PY_MAJOR_VERSION > 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8) - def("__index__", [](Type value) { return (Scalar) value; }); - #endif - attr("__setstate__") = cpp_function( [](detail::value_and_holder &v_h, Scalar arg) { detail::initimpl::setstate(v_h, static_cast(arg),