Skip to content

Commit

Permalink
Fix for bad behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Sep 29, 2017
1 parent b02e440 commit 904781f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ template <typename Type> class enum_ : public class_<Type> {

template <typename... Extra>
enum_(const handle &scope, const char *name, const Extra&... extra)
: class_<Type>(scope, name, extra...), m_entries(), m_parent(scope), m_name(name) {
: class_<Type>(scope, name, extra...), m_entries(), m_parent(scope) {

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

Expand All @@ -1377,14 +1377,14 @@ template <typename Type> class enum_ : public class_<Type> {
return m;
}, return_value_policy::copy);
def(init([](Scalar i) { return static_cast<Type>(i); }));
def(init([this, m_entries_ptr](std::string value) -> Type {
def(init([name, m_entries_ptr](std::string value) -> Type {
for (const auto &kv : reinterpret_borrow<dict>(m_entries_ptr)) {
std::string key = cast<str>(kv.first);
if(value == key || key == m_name + "::" + value) {
if(value == key || key == std::string(name) + "::" + value) {
return cast<Type>(kv.second);
}
}
throw value_error("\"" + value + "\" is not a valid value for enum type " + m_name);
throw value_error("\"" + value + "\" is not a valid value for enum type " + name);
}));
def("__int__", [](Type value) { return (Scalar) value; });
#if PY_MAJOR_VERSION < 3
Expand Down Expand Up @@ -1445,7 +1445,6 @@ template <typename Type> class enum_ : public class_<Type> {
private:
dict m_entries;
handle m_parent;
std::string m_name;
};

NAMESPACE_BEGIN(detail)
Expand Down

0 comments on commit 904781f

Please sign in to comment.