Skip to content

Commit

Permalink
Revert "Using simpler entries capture from @jagerman"
Browse files Browse the repository at this point in the history
This reverts commit 2d440e0.
  • Loading branch information
henryiii committed Oct 11, 2017
1 parent 0102e67 commit e5409ce
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -1362,23 +1362,23 @@ template <typename Type> class enum_ : public class_<Type> {

constexpr bool is_arithmetic = detail::any_of<std::is_same<arithmetic, Extra>...>::value;

dict& entries = m_entries;
def("__repr__", [name, entries](Type value) -> pybind11::str {
for (const auto &kv : entries) {
auto m_entries_ptr = m_entries.inc_ref().ptr();
def("__repr__", [name, m_entries_ptr](Type value) -> pybind11::str {
for (const auto &kv : reinterpret_borrow<dict>(m_entries_ptr)) {
if (pybind11::cast<Type>(kv.second) == value)
return pybind11::str("{}.{}").format(name, kv.first);
}
return pybind11::str("{}.???").format(name);
});
def_property_readonly_static("__members__", [entries](object /* self */) {
def_property_readonly_static("__members__", [m_entries_ptr](object /* self */) {
dict m;
for (const auto &kv : entries)
for (const auto &kv : reinterpret_borrow<dict>(m_entries_ptr))
m[kv.first] = kv.second;
return m;
}, return_value_policy::copy);
def(init([](Scalar i) { return static_cast<Type>(i); }));
def(init([name, entries](std::string value) -> Type {
pybind11::dict values = entries;
def(init([name, m_entries_ptr](std::string value) -> Type {
pybind11::dict values = reinterpret_borrow<pybind11::dict>(m_entries_ptr);
pybind11::str key = pybind11::str(value);
if (values.contains(key))
return pybind11::cast<Type>(values[key]);
Expand Down

0 comments on commit e5409ce

Please sign in to comment.