@@ -1362,23 +1362,23 @@ template <typename Type> class enum_ : public class_<Type> {
1362
1362
1363
1363
constexpr bool is_arithmetic = detail::any_of<std::is_same<arithmetic, Extra>...>::value;
1364
1364
1365
- dict& entries = m_entries;
1366
- def (" __repr__" , [name, entries ](Type value) -> pybind11::str {
1367
- for (const auto &kv : entries ) {
1365
+ auto m_entries_ptr = m_entries. inc_ref (). ptr () ;
1366
+ def (" __repr__" , [name, m_entries_ptr ](Type value) -> pybind11::str {
1367
+ for (const auto &kv : reinterpret_borrow<dict>(m_entries_ptr) ) {
1368
1368
if (pybind11::cast<Type>(kv.second ) == value)
1369
1369
return pybind11::str (" {}.{}" ).format (name, kv.first );
1370
1370
}
1371
1371
return pybind11::str (" {}.???" ).format (name);
1372
1372
});
1373
- def_property_readonly_static (" __members__" , [entries ](object /* self */ ) {
1373
+ def_property_readonly_static (" __members__" , [m_entries_ptr ](object /* self */ ) {
1374
1374
dict m;
1375
- for (const auto &kv : entries )
1375
+ for (const auto &kv : reinterpret_borrow<dict>(m_entries_ptr) )
1376
1376
m[kv.first ] = kv.second ;
1377
1377
return m;
1378
1378
}, return_value_policy::copy);
1379
1379
def (init ([](Scalar i) { return static_cast <Type>(i); }));
1380
- def (init ([name, entries ](std::string value) -> Type {
1381
- pybind11::dict values = entries ;
1380
+ def (init ([name, m_entries_ptr ](std::string value) -> Type {
1381
+ pybind11::dict values = reinterpret_borrow<pybind11::dict>(m_entries_ptr) ;
1382
1382
pybind11::str key = pybind11::str (value);
1383
1383
if (values.contains (key))
1384
1384
return pybind11::cast<Type>(values[key]);
0 commit comments