Skip to content

Commit 8e279ac

Browse files
committed
Fix for bad this behavior
1 parent b02e440 commit 8e279ac

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

include/pybind11/pybind11.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ template <typename Type> class enum_ : public class_<Type> {
13581358

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

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

@@ -1377,14 +1377,14 @@ template <typename Type> class enum_ : public class_<Type> {
13771377
return m;
13781378
}, return_value_policy::copy);
13791379
def(init([](Scalar i) { return static_cast<Type>(i); }));
1380-
def(init([this, m_entries_ptr](std::string value) -> Type {
1380+
def(init([name, m_entries_ptr](std::string value) -> Type {
13811381
for (const auto &kv : reinterpret_borrow<dict>(m_entries_ptr)) {
1382-
std::string key = cast<str>(kv.first);
1383-
if(value == key || key == m_name + "::" + value) {
1384-
return cast<Type>(kv.second);
1382+
std::string key = pybind11::cast<pybind11::str>(kv.first);
1383+
if (value == key) {
1384+
return pybind11::cast<Type>(kv.second);
13851385
}
13861386
}
1387-
throw value_error("\"" + value + "\" is not a valid value for enum type " + m_name);
1387+
throw value_error("\"" + value + "\" is not a valid value for enum type " + name);
13881388
}));
13891389
def("__int__", [](Type value) { return (Scalar) value; });
13901390
#if PY_MAJOR_VERSION < 3
@@ -1445,7 +1445,6 @@ template <typename Type> class enum_ : public class_<Type> {
14451445
private:
14461446
dict m_entries;
14471447
handle m_parent;
1448-
std::string m_name;
14491448
};
14501449

14511450
NAMESPACE_BEGIN(detail)

tests/test_enum.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def test_unscoped_enum():
4141
assert not (m.UnscopedEnum.ETwo < m.UnscopedEnum.EOne)
4242
assert not (2 < m.UnscopedEnum.EOne)
4343

44+
4445
def test_converstion_enum():
4546
assert m.test_conversion_enum(m.ConversionEnum.Convert1) == "ConversionEnum::Convert1"
4647
assert m.test_conversion_enum(m.ConversionEnum("Convert1")) == "ConversionEnum::Convert1"

0 commit comments

Comments
 (0)