File tree Expand file tree Collapse file tree 2 files changed +3
-8
lines changed Expand file tree Collapse file tree 2 files changed +3
-8
lines changed Original file line number Diff line number Diff line change @@ -59,12 +59,8 @@ struct enum_type_caster {
59
59
base_caster base;
60
60
if (base.load (src, convert)) {
61
61
T v = static_cast <T>(base);
62
- if (::google::protobuf::GetEnumDescriptor<EnumType>()->FindValueByNumber (v) ==
63
- nullptr ) {
64
- throw pybind11::value_error (" Invalid value " + std::to_string (v) +
65
- " for ::google::protobuf::Enum " +
66
- pybind11::type_id<EnumType>());
67
- }
62
+ // Behavior change 2023-07-19: Previously we only accept integers that
63
+ // are valid values of the enum.
68
64
value = static_cast <EnumType>(v);
69
65
return true ;
70
66
}
Original file line number Diff line number Diff line change @@ -19,8 +19,7 @@ def test_enum(self):
19
19
self .assertEqual (
20
20
m .adjust_enum (test_pb2 .TestMessage .ONE ), test_pb2 .TestMessage .TWO )
21
21
self .assertEqual (m .adjust_enum (m .ZERO ), m .ONE )
22
- with self .assertRaises (ValueError ):
23
- m .adjust_enum (7 )
22
+ self .assertEqual (m .adjust_enum (7 ), m .ZERO )
24
23
with self .assertRaises (TypeError ):
25
24
m .adjust_enum ('ZERO' )
26
25
You can’t perform that action at this time.
0 commit comments