restores __invert__ to arithmetic-enabled enum, fixes #1907 (#1909)

This commit is contained in:
Lori A. Burns 2019-09-04 16:16:21 -04:00 committed by Wenzel Jakob
parent 5b4751af26
commit f6c4c1047a
2 changed files with 3 additions and 0 deletions

View File

@ -1484,6 +1484,8 @@ struct enum_base {
PYBIND11_ENUM_OP_CONV("__ror__", a | b); PYBIND11_ENUM_OP_CONV("__ror__", a | b);
PYBIND11_ENUM_OP_CONV("__xor__", a ^ b); PYBIND11_ENUM_OP_CONV("__xor__", a ^ b);
PYBIND11_ENUM_OP_CONV("__rxor__", a ^ b); PYBIND11_ENUM_OP_CONV("__rxor__", a ^ b);
m_base.attr("__invert__") = cpp_function(
[](object arg) { return ~(int_(arg)); }, is_method(m_base));
} }
} else { } else {
PYBIND11_ENUM_OP_STRICT("__eq__", int_(a).equal(int_(b)), return false); PYBIND11_ENUM_OP_STRICT("__eq__", int_(a).equal(int_(b)), return false);

View File

@ -140,6 +140,7 @@ def test_binary_operators():
assert int(m.Flags.Read | m.Flags.Execute) == 5 assert int(m.Flags.Read | m.Flags.Execute) == 5
assert int(m.Flags.Write | m.Flags.Execute) == 3 assert int(m.Flags.Write | m.Flags.Execute) == 3
assert int(m.Flags.Write | 1) == 3 assert int(m.Flags.Write | 1) == 3
assert ~m.Flags.Write == -3
state = m.Flags.Read | m.Flags.Write state = m.Flags.Read | m.Flags.Write
assert (state & m.Flags.Read) != 0 assert (state & m.Flags.Read) != 0