Skip to content

Commit

Permalink
fix: __index__ on Enum should always be present. (#3700)
Browse files Browse the repository at this point in the history
* chore: minor odd py version cleanup

* Update include/pybind11/pybind11.h

* fix: always make __index__ available
  • Loading branch information
henryiii authored Feb 8, 2022
1 parent 1b84188 commit af056b6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 7 deletions.
3 changes: 0 additions & 3 deletions include/pybind11/detail/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -1911,13 +1911,10 @@ template <typename Type> class enum_ : public class_<Type> {
def(init([](Scalar i) { return static_cast<Type>(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<Base>(v_h, static_cast<Type>(arg),
Expand Down

0 comments on commit af056b6

Please sign in to comment.