Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property docstrings not handled correctly in version 1.0 #117

Closed
abhinavnatarajan opened this issue Aug 30, 2023 · 3 comments · Fixed by #118
Closed

Property docstrings not handled correctly in version 1.0 #117

abhinavnatarajan opened this issue Aug 30, 2023 · 3 comments · Fixed by #118
Assignees
Labels
bug Something isn't working

Comments

@abhinavnatarajan
Copy link

Property docstrings are no longer handled correctly in version 1.0 and above, for the following reasons:

  1. The method ExtractSignaturesFromPybind11Docstrings.handle_property defined in pybind11_stubgen.parser.mixins.parse does not populate the doc attribute of the Property object that is returned. Property objects defined by pybind11 attach the docstring to the property object and a signature to the fget method, and the output stubs from pybind11-stubgen only contain the latter.
  2. Printer.print_property from pybind11_stubgen.printer does not insert the property docstring into the result.
  3. The class ReplaceReadWritePropertyWithField replaces class properties with class attributes, but attributes and properties are fundamentally different. Properties can have docstrings, while attributes cannot. Moreover, documentation generators like the autodoc extension in Sphinx treat properties and attributes differently. The upshot is that ReplaceReadWritePropertyWithField causes any docstrings written for a property to get removed, and for that property to be documented as an attribute.

Context: I'm using pybind11-stubgen to generate stubs and docstrings for my pybind11 project, which I then use in Sphinx to autogenerate documentation. This works better than using Sphinx directly on the extension module generated by pybind11 because the code generated by pybind11 cannot be inspected for PEP 484 style annotations, which breaks some functionality of sphinx.ext.autodoc.

@sizmailov sizmailov added the bug Something isn't working label Aug 30, 2023
@sizmailov sizmailov self-assigned this Aug 30, 2023
@sizmailov
Copy link
Owner

Thanks for the detailed report.

Could you check that #118 works as expected?

pip install git+https://github.com/sizmailov/pybind11-stubgen.git@fix-missing-property-docstrings

@sizmailov
Copy link
Owner

@abhinavnatarajan I went ahead and merged the fix. Feel free to reopen/create new one.

@abhinavnatarajan
Copy link
Author

That seems to have fixed the issue. Many thanks for your great work on this package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants