Uh oh!
There was an error while loading. Please reload this page.
Add option for enable/disable enum members in docstring. - #2768
Conversation
YannickJadoul
commented
Jan 5, 2021
Two things:
|
knarfS
commented
Jan 5, 2021
I wanted to put this in the same place as the other docstring related options (
There is still the docstring of the enum class itself ( |
YannickJadoul
commented
Jan 5, 2021
Yeah, I'm not 100% convinced of either approach, but I thought it's worth bringing up). If there are no further complaints, I'm happy to keep the global option, though.
I believe that if you don't set |
knarfS
commented
Jan 5, 2021
You are right, I've just tested this and it works! |
YannickJadoul
commented
Jan 5, 2021
Thanks, that's already better, I think :-)
Just to add to future discussion (I'm still not saying this is preferred): if we want to get around this, another option is to come up with some custom tag like |
knarfS
commented
Jan 6, 2021
This will also fix #2275 when disabling the enum members docstring (aka not setting # include<pybind11/pybind11.h>namespacepy= pybind11;
enum Numbers {
zero,
one
}
PYBIND11_MODULE(numbers, m) {
py::options options;
options.disable_enum_members_docstring();
py::enum_<Numbers>e(m, "Numbers");
e
.value("zero", zero)
.value("one", one)
.export_values();
e.attr("__doc__") = "test";
} |
YannickJadoul
commented
Jan 6, 2021
Thanks for checking that as well, @knarfS! |
rwgk
commented
Dec 1, 2022
Looks good to me, based on the understanding that this PR adds an option with a default that leaves the existing behavior unchanged, unless the option is actually used. Is that correct? The only thing missing are tests and possibly a couple lines in the documentation (I'd look for documentation for existing options as a starting point). |
knarfS
commented
Dec 2, 2022
Yes, the current docstring behavior is untouched. I've added a test to secure that. I've also added a section about the undocumented option |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
knarfS
commented
Dec 2, 2022
Thank you @rwgk for reviewing and approving. I updated the PR with your suggestions. |
rwgk
commented
Dec 2, 2022
Great, thanks! I'll wait a day or so to give @Skylion007 I chance to review, too. |
| dict entries = arg.attr("__entries"); | ||
| if (((PyTypeObject *) arg.ptr())->tp_doc) { | ||
| docstring | ||
| += std::string(((PyTypeObject *) arg.ptr())->tp_doc) + "\n\n"; |
| auto comment = kv.second[int_(1)]; | ||
| docstring += "\n\n " + key; | ||
| if (!comment.is_none()) { | ||
| docstring += " : " + (std::string) pybind11::str(comment); |
There was a problem hiding this comment.
nit: static_cast or .cast<std::string>
There was a problem hiding this comment.
Also applied in Applied in commit c2456d9
I also changed the code to systematically use +=.
Skylion007
commented
Dec 9, 2022
Sorry, missed this in my Github notifications. |
rwgk
commented
Dec 9, 2022
I went ahead with a rebase & applying the review suggestions, to get this into the next smart_holder update. Waiting for the CI. |
rwgk
commented
Dec 9, 2022
The only one CI failure is a known flake (test_gil_scoped DEADLOCK), definitely unrelated to this RP. |
knarfS
commented
Dec 11, 2022
Thanks @rwgk for merging! Not sure, but maybe #2275 can be also closed now (see test above). |
rwgk
commented
Dec 11, 2022
@AWhetter Is there a chance you could confirm & update or close #2275? |
AWhetter
commented
Dec 12, 2022
This does indeed fix that issue! |
rwgk
commented
Dec 12, 2022
Thanks @AWhetter! |
Description
This adds the option to disable/enable the enum members listed in the docstring (default is enabled). This is useful, when the documentation tool is able to generate documentation for class variables, so the enum members / class variable aren't listed twice in the documentation. An other benefit of using the features of the documentation generator is, that the members are linkable in the documentation.
I'm using pdoc3 to generate the documentation of an embedded python module, but the above also applies partially to pydoc. No idea about sphinx, I wasn't able to generate the documentation programmatically with sphinx...
I'd be happy to add that option to the documentation, but need a hint to which section this would fit best. There is a chapter about sphinx, but that doesn't exactly match.
Suggested changelog entry: