@@ -1708,15 +1708,30 @@ template <typename Type> class enum_ : public class_<Type> {
1708
1708
auto m_entries_ptr = m_entries.inc_ref ().ptr ();
1709
1709
def (" __repr__" , [name, m_entries_ptr](Type value) -> pybind11::str {
1710
1710
for (const auto &kv : reinterpret_borrow<dict>(m_entries_ptr)) {
1711
- if (pybind11::cast<Type>(kv.second ) == value)
1711
+ if (pybind11::cast<Type>(kv.second [ int_ ( 0 )] ) == value)
1712
1712
return pybind11::str (" {}.{}" ).format (name, kv.first );
1713
1713
}
1714
1714
return pybind11::str (" {}.???" ).format (name);
1715
1715
});
1716
- def_property_readonly_static (" __members__" , [m_entries_ptr](object /* self */ ) {
1716
+ def_property_readonly_static (" __doc__" , [m_entries_ptr](handle self) {
1717
+ std::string docstring;
1718
+ const char *tp_doc = ((PyTypeObject *) self.ptr ())->tp_doc ;
1719
+ if (tp_doc)
1720
+ docstring += std::string (tp_doc) + " \n\n " ;
1721
+ docstring += " Members:" ;
1722
+ for (const auto &kv : reinterpret_borrow<dict>(m_entries_ptr)) {
1723
+ auto key = std::string (pybind11::str (kv.first ));
1724
+ auto comment = kv.second [int_ (1 )];
1725
+ docstring += " \n\n " + key;
1726
+ if (!comment.is_none ())
1727
+ docstring += " : " + (std::string) pybind11::str (comment);
1728
+ }
1729
+ return docstring;
1730
+ });
1731
+ def_property_readonly_static (" __members__" , [m_entries_ptr](handle /* self */ ) {
1717
1732
dict m;
1718
1733
for (const auto &kv : reinterpret_borrow<dict>(m_entries_ptr))
1719
- m[kv.first ] = kv.second ;
1734
+ m[kv.first ] = kv.second [ int_ ( 0 )] ;
1720
1735
return m;
1721
1736
}, return_value_policy::copy);
1722
1737
def (init ([](Scalar i) { return static_cast <Type>(i); }));
@@ -1764,15 +1779,15 @@ template <typename Type> class enum_ : public class_<Type> {
1764
1779
// / Export enumeration entries into the parent scope
1765
1780
enum_& export_values () {
1766
1781
for (const auto &kv : m_entries)
1767
- m_parent.attr (kv.first ) = kv.second ;
1782
+ m_parent.attr (kv.first ) = kv.second [ int_ ( 0 )] ;
1768
1783
return *this ;
1769
1784
}
1770
1785
1771
1786
// / Add an enumeration entry
1772
- enum_& value (char const * name, Type value) {
1787
+ enum_& value (char const * name, Type value, const char *doc = nullptr ) {
1773
1788
auto v = pybind11::cast (value, return_value_policy::copy);
1774
1789
this ->attr (name) = v;
1775
- m_entries[pybind11::str (name)] = v ;
1790
+ m_entries[pybind11::str (name)] = std::make_pair (v, doc) ;
1776
1791
return *this ;
1777
1792
}
1778
1793
0 commit comments