From 594330d4d9405bd5d956253aefd18cd7cbf778b8 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 7 Feb 2022 22:56:10 -0500 Subject: [PATCH 1/3] chore: minor odd py version cleanup --- include/pybind11/detail/common.h | 3 --- include/pybind11/pybind11.h | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index d9f838236a..14788b6523 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 7aa93bb5aa..0ed5dfa74b 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1913,8 +1913,7 @@ template class enum_ : public class_ { def("__int__", [](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) + #else def("__index__", [](Type value) { return (Scalar) value; }); #endif From 33a8a08229087abb135d894b1df0029878cddfe9 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 8 Feb 2022 10:14:04 -0500 Subject: [PATCH 2/3] Update include/pybind11/pybind11.h --- include/pybind11/pybind11.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 0ed5dfa74b..4bb3903b44 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1913,7 +1913,7 @@ template class enum_ : public class_ { def("__int__", [](Type value) { return (Scalar) value; }); #if PY_MAJOR_VERSION < 3 def("__long__", [](Type value) { return (Scalar) value; }); - #else + #elif PY_VERSION_HEX >= 0x03080000 def("__index__", [](Type value) { return (Scalar) value; }); #endif From 40486eaa47ae1aa14568d763ebfd11566aeda421 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 8 Feb 2022 10:20:57 -0500 Subject: [PATCH 3/3] fix: always make __index__ available --- include/pybind11/pybind11.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 4bb3903b44..7dcea95b42 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1911,12 +1911,10 @@ template class enum_ : public class_ { 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; }); - #elif PY_VERSION_HEX >= 0x03080000 - 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),