aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWenzel Jakob <wenzel.jakob@epfl.ch>2019-09-20 11:06:10 +0200
committerWenzel Jakob <wenzel.jakob@epfl.ch>2019-09-20 11:06:10 +0200
commit31680e6f9c1bbe582bc36d457f8e010121ff16bb (patch)
tree532742cf4f5f68cf823df4243fdd0fdd5f70bc82
parent5fd187ebe92b3fbd3e467a08c194dc254a1edd74 (diff)
downloadplatform_external_python_pybind11-31680e6f9c1bbe582bc36d457f8e010121ff16bb.tar.gz
platform_external_python_pybind11-31680e6f9c1bbe582bc36d457f8e010121ff16bb.tar.bz2
platform_external_python_pybind11-31680e6f9c1bbe582bc36d457f8e010121ff16bb.zip
Implicit conversion from enum to int for Python 3.8 (fix by @sizmailov)
-rw-r--r--include/pybind11/pybind11.h4
-rw-r--r--tests/test_enum.py15
2 files changed, 10 insertions, 9 deletions
diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h
index 204aaa4..a0e6395 100644
--- a/include/pybind11/pybind11.h
+++ b/include/pybind11/pybind11.h
@@ -1566,6 +1566,10 @@ public:
#if PY_MAJOR_VERSION < 3
def("__long__", [](Type value) { return (Scalar) value; });
#endif
+ #if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 8
+ def("__index__", [](Type value) { return (Scalar) value; });
+ #endif
+
cpp_function setstate(
[](Type &value, Scalar arg) { value = static_cast<Type>(arg); },
is_method(*this));
diff --git a/tests/test_enum.py b/tests/test_enum.py
index cea834d..7fe9b61 100644
--- a/tests/test_enum.py
+++ b/tests/test_enum.py
@@ -192,15 +192,12 @@ def test_binary_operators():
def test_enum_to_int():
- import sys
- # Implicit conversion to integers is deprecated in Python >= 3.8
- if sys.version_info < (3, 8):
- m.test_enum_to_int(m.Flags.Read)
- m.test_enum_to_int(m.ClassWithUnscopedEnum.EMode.EFirstMode)
- m.test_enum_to_uint(m.Flags.Read)
- m.test_enum_to_uint(m.ClassWithUnscopedEnum.EMode.EFirstMode)
- m.test_enum_to_long_long(m.Flags.Read)
- m.test_enum_to_long_long(m.ClassWithUnscopedEnum.EMode.EFirstMode)
+ m.test_enum_to_int(m.Flags.Read)
+ m.test_enum_to_int(m.ClassWithUnscopedEnum.EMode.EFirstMode)
+ m.test_enum_to_uint(m.Flags.Read)
+ m.test_enum_to_uint(m.ClassWithUnscopedEnum.EMode.EFirstMode)
+ m.test_enum_to_long_long(m.Flags.Read)
+ m.test_enum_to_long_long(m.ClassWithUnscopedEnum.EMode.EFirstMode)
def test_duplicate_enum_name():