File tree Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -1378,13 +1378,12 @@ template <typename Type> class enum_ : public class_<Type> {
13781378 }, return_value_policy::copy);
13791379 def (init ([](Scalar i) { return static_cast <Type>(i); }));
13801380 def (init ([name, m_entries_ptr](std::string value) -> Type {
1381- for (const auto &kv : reinterpret_borrow<dict>(m_entries_ptr)) {
1382- std::string key = pybind11::cast<pybind11::str>(kv.first );
1383- if (value == key) {
1384- return pybind11::cast<Type>(kv.second );
1385- }
1386- }
1387- throw value_error (" \" " + value + " \" is not a valid value for enum type " + name);
1381+ pybind11::dict values = reinterpret_borrow<pybind11::dict>(m_entries_ptr);
1382+ pybind11::str key = pybind11::str (value);
1383+ if (values.contains (key))
1384+ return pybind11::cast<Type>(values[key]);
1385+ else
1386+ throw value_error (" \" " + value + " \" is not a valid value for enum type " + name);
13881387 }));
13891388 def (" __int__" , [](Type value) { return (Scalar) value; });
13901389 #if PY_MAJOR_VERSION < 3
You can’t perform that action at this time.
0 commit comments