Skip to content

Commit c8e9f3c

Browse files
committed
quench __setstate__ warnings (fixes #1522)
1 parent ef13fb2 commit c8e9f3c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

include/pybind11/pybind11.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,9 +1503,11 @@ NAMESPACE_END(detail)
15031503
/// Binds C++ enumerations and enumeration classes to Python
15041504
template <typename Type> class enum_ : public class_<Type> {
15051505
public:
1506-
using class_<Type>::def;
1507-
using class_<Type>::def_property_readonly;
1508-
using class_<Type>::def_property_readonly_static;
1506+
using Base = class_<Type>;
1507+
using Base::def;
1508+
using Base::attr;
1509+
using Base::def_property_readonly;
1510+
using Base::def_property_readonly_static;
15091511
using Scalar = typename std::underlying_type<Type>::type;
15101512

15111513
template <typename... Extra>
@@ -1520,7 +1522,10 @@ template <typename Type> class enum_ : public class_<Type> {
15201522
#if PY_MAJOR_VERSION < 3
15211523
def("__long__", [](Type value) { return (Scalar) value; });
15221524
#endif
1523-
def("__setstate__", [](Type &value, Scalar arg) { value = static_cast<Type>(arg); });
1525+
cpp_function setstate(
1526+
[](Type &value, Scalar arg) { value = static_cast<Type>(arg); },
1527+
is_method(*this));
1528+
attr("__setstate__") = setstate;
15241529
}
15251530

15261531
/// Export enumeration entries into the parent scope

0 commit comments

Comments
 (0)