@@ -1570,23 +1570,6 @@ inline str enum_name(handle arg) {
1570
1570
return " ???" ;
1571
1571
}
1572
1572
1573
- template <typename Type, typename Scalar, bool is_convertible = true >
1574
- struct enum_value {
1575
- static Scalar run (handle arg) {
1576
- Type value = pybind11::cast<Type>(arg);
1577
- return static_cast <Scalar>(value);
1578
- }
1579
- };
1580
-
1581
- template <typename Type, typename Scalar>
1582
- struct enum_value <Type, Scalar, false > {
1583
- static Scalar run (handle) {
1584
- throw pybind11::cast_error (
1585
- " Enum for " + type_id<Type>() + " is not convertible to " +
1586
- type_id<Scalar>());
1587
- }
1588
- };
1589
-
1590
1573
struct enum_base {
1591
1574
enum_base (handle base, handle parent) : m_base(base), m_parent(parent) { }
1592
1575
@@ -1737,6 +1720,7 @@ template <typename Type> class enum_ : public class_<Type> {
1737
1720
using Base = class_<Type>;
1738
1721
using Base::def;
1739
1722
using Base::attr;
1723
+ using Base::def_property;
1740
1724
using Base::def_property_readonly;
1741
1725
using Base::def_property_readonly_static;
1742
1726
using Scalar = typename std::underlying_type<Type>::type;
@@ -1746,15 +1730,10 @@ template <typename Type> class enum_ : public class_<Type> {
1746
1730
: class_<Type>(scope, name, extra...), m_base(*this , scope) {
1747
1731
constexpr bool is_arithmetic = detail::any_of<std::is_same<arithmetic, Extra>...>::value;
1748
1732
constexpr bool is_convertible = std::is_convertible<Type, Scalar>::value;
1749
- auto property = handle ((PyObject *) &PyProperty_Type);
1750
1733
m_base.init (is_arithmetic, is_convertible);
1751
1734
1752
- attr (" value" ) = property (
1753
- cpp_function (
1754
- &detail::enum_value<Type, Scalar, is_convertible>::run,
1755
- pybind11::name (" value" ), is_method (*this )));
1756
-
1757
1735
def (init ([](Scalar i) { return static_cast <Type>(i); }), arg (" value" ));
1736
+ def_property (" value" , [](Type value) { return (Scalar) value; }, nullptr );
1758
1737
def (" __int__" , [](Type value) { return (Scalar) value; });
1759
1738
#if PY_MAJOR_VERSION < 3
1760
1739
def (" __long__" , [](Type value) { return (Scalar) value; });
0 commit comments