mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-11 08:03:55 +00:00
Implicit conversion from enum to int for Python 3.8 (fix by @sizmailov)
This commit is contained in:
parent
5fd187ebe9
commit
31680e6f9c
@ -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));
|
||||
|
@ -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():
|
||||
|
Loading…
Reference in New Issue
Block a user