Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
31680e6f
Commit
31680e6f
authored
Sep 20, 2019
by
Wenzel Jakob
Browse files
Implicit conversion from enum to int for Python 3.8 (fix by @sizmailov)
parent
5fd187eb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
9 deletions
+10
-9
include/pybind11/pybind11.h
include/pybind11/pybind11.h
+4
-0
tests/test_enum.py
tests/test_enum.py
+6
-9
No files found.
include/pybind11/pybind11.h
View file @
31680e6f
...
...
@@ -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
));
...
...
tests/test_enum.py
View file @
31680e6f
...
...
@@ -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
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment