mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
enum_: fix implicit conversion on Python 2.7
Enumerations on Python 2.7 were not always implicitly converted to integers (depending on the target size). This patch adds a __long__ conversion function (only enabled on 2.7) which fixes this issue. The attached test case fails without this patch.
This commit is contained in:
@@ -115,3 +115,14 @@ def test_binary_operators():
|
||||
state2 = ~state
|
||||
assert state2 == -7
|
||||
assert int(state ^ state2) == -1
|
||||
|
||||
def test_enum_to_int():
|
||||
from pybind11_tests import Flags, ClassWithUnscopedEnum
|
||||
from pybind11_tests import test_enum_to_int, test_enum_to_uint, test_enum_to_long_long
|
||||
|
||||
test_enum_to_int(Flags.Read)
|
||||
test_enum_to_int(ClassWithUnscopedEnum.EMode.EFirstMode)
|
||||
test_enum_to_uint(Flags.Read)
|
||||
test_enum_to_uint(ClassWithUnscopedEnum.EMode.EFirstMode)
|
||||
test_enum_to_long_long(Flags.Read)
|
||||
test_enum_to_long_long(ClassWithUnscopedEnum.EMode.EFirstMode)
|
||||
|
||||
Reference in New Issue
Block a user