Uh oh!
There was an error while loading. Please reload this page.
[READY] Implement an enum_ property "name" - #1345
Conversation
| def_property_readonly("name", [m_entries_ptr](Type value) -> pybind11::str { | ||
| for (const auto &kv : reinterpret_borrow<dict>(m_entries_ptr)) { | ||
| if (pybind11::cast<Type>(kv.second[int_(0)]) == value) | ||
| return pybind11::str("{}").format(kv.first); |
There was a problem hiding this comment.
Going through format here is unnecessary: this can just be: return pybind11::str(kv.first);
bstaletic
commented
Apr 5, 2018
I have added the documentation and addressed the review comment. |
| .. note:: | ||
| It is also possible to use ``py::str(enum)``, however these accomplish different |
There was a problem hiding this comment.
Typo: that should just be str(enum) (i.e. no py::), since this is a Python reference.
One minor doc fix, but then it looks good to me. One other comment to add in support of this PR: Python 3 (or older Pythons with |
The property returns the enum_ value as a string. For example: >>> import module >>> module.enum.VALUE enum.VALUE >>> str(module.enum.VALUE) 'enum.VALUE' >>> module.enum.VALUE.name 'VALUE' This is actually the equivalent of Boost.Python "name" property.
bstaletic
commented
Apr 6, 2018
The |
The property returns the enum_ value as a string.
For example:
This is actually the equivalent of Boost.Python "name" property.
@jagerman Pointed out #1122 as it is somewhat related. The reason I didn't propose this change there is because I believe that smaller changes are easier to both reason about and review.