Closed 2bndy5 closed 2 years ago
The issue appears to be with autodoc_property_type.py
This has caused issues before --- it would probably be nice if we had a unit test to check for issues and prevent regressions. I think using pybind11 in the build process will be more trouble than it is worth, but perhaps we can simulate it.
I was thinking of building docs for one of the pybind11 example repos, but that may also catch bugs in pybind11.
Currently pybind11 doesn't append provided docstrings for class attributes...
Can you perhaps create a self-contained example as a test case?
In trying to create a simple example project, I think I narrowed it down to class instance attributes. Although, I'm starting to get the feeling that this may have something to do with the builtin "magic" methods that pybind11 automatically adds...
The pybind11-doc-test project resembles the original repo in which I discovered this issue (just super simplified).
__init__()
and add()
) of the class are overloaded to check it had nothing to do with using custom signatures embedded in the docstrings.The sample's docs are designed to show the error (currently broken).
:members:
option.I plan on uploading this sample project to test.pypi, so we can run pytest with it in this repo's CI.
oh yea, check the doc-test project's CI artifacts for the built wheels (currently only targeting the OSs used in github runners)
Thanks. I think potentially it would make sense to just include the main.cpp
and a minimal setup.py
-based build as a test within the sphinx-immaterial repo --- using setup.py would probably be simple than relying on cmake.
How do want to rope in the pybind11 source? In the sample project, I used CMake. In the the pyrf24 project, I used a git submodule.
It appears to be available on pypi.
took me a while to figure out how to do it without cmake, but see #145
been looking into the autodoc_proprerty.py, and I found an unused var (fget
):
https://github.com/jbms/sphinx-immaterial/blob/412922e592318f261d7d1e965e9716f69afefa98/sphinx_immaterial/apidoc/python/autodoc_property_type.py#L28-L40
fget
isn't actually used. However, this issue wasn't resolved when I changed
- doc = obj.__doc__
+ doc = fget.__doc__
The working solution I did find was to make https://github.com/jbms/sphinx-immaterial/blob/412922e592318f261d7d1e965e9716f69afefa98/sphinx_immaterial/apidoc/python/autodoc_property_type.py#L19-L25
only return sphinx.util.inspect.safe_getattr(obj, "func", None)
I found a peculiarity in pybind11 concerning a class' property's fget.__doc__
.
If I build the test pkg using a singular module structure:
- sphinx-immaterial-pybind11-issue-134
- setup.py
- sphinx_immaterial_pybind11_issue_134.cpp
then Example.is_set_by_init.fget.__doc__
is as expected:
(self: sphinx_immaterial_pybind11_issue_134.Example) -> bool
rich.inspect()
But, if I build the test pkg using a pkg src folder:
- sphinx-immaterial-pybind11-issue-134
- setup.py
- src
- sphinx_immaterial_pybind11_issue_134.cpp
Then Example.is_set_by_init.fget.__doc__
is not set at all.
return_annotation = None
in theSignature
object used to parse the property in sphinx_immaterial/apigen/python/autodoc_property_type.py
rich.inspect()
So, I don't think the return type annotation for class properties can be fully supported in pybind11 wrapped pkgs. Technically, I think this may be a bug in pybind11, but that's not our concern here. We just want the property's basic signature at least.
I'm a bit confused --- for me, regardless of whether the C++ source file in a src/
directory or not, I'm seeing: sphinx_immaterial_pybind11_issue_134.Example.is_set_by_init.fget.__doc__
equal to None
FYI, I just did a recently release of the problematic repo, pyrf24, where I moved the binding code out of the repo's src/pkg_name/ folder (its now just in src/) in an effort to discontinue using scikit-build pkg. I'm not sure how this may have effected the issue here...
I say this because I because (using the latest release of pyrf24) the members
option seems to work with your fix from #142 . I also get expected results from my suggested fix in https://github.com/jbms/sphinx-immaterial/pull/142#issuecomment-1216481744. I'm not sure which solution you want to use; I leave that up to you.
As it stands I think #145 is an accurate production of this issue because it does fail without the fix in #142 . I'll mark it ready to merge, so I can move on from this problem.
I'm not concerned with getting the docstring from c-extended class properties' fget()
because it is a pybind11 problem. Maybe we can revisit that edge case later, but I want to get back to more important things (like finishing the cpp-apigen ext).
fixed in v0.9.0
Latest release (v0.8.0) seems to have broken the use of the
autoclass
directive's:members:
option. I'm getting the following unhelpful errorThe traceback isn't helpful at all. the only thing I notice from the error message is that the object's name is missing:
objtype ?? at offset
.full traceback
``` Traceback (most recent call last): File "/mnt/c/Users/username/Documents/GitHub/env/lib/python3.10/site-packages/sphinx/util/inspect.py", line 576, in signature signature = inspect.signature(subject, follow_wrapped=True) File "/usr/local/lib/python3.10/inspect.py", line 3245, in signature return Signature.from_callable(obj, follow_wrapped=follow_wrapped, File "/usr/local/lib/python3.10/inspect.py", line 2993, in from_callable return _signature_from_callable(obj, sigcls=cls, File "/usr/local/lib/python3.10/inspect.py", line 2459, in _signature_from_callable return _signature_from_builtin(sigcls, obj, File "/usr/local/lib/python3.10/inspect.py", line 2269, in _signature_from_builtin raise ValueError("no signature found for builtin {!r}".format(func)) ValueError: no signature found for builtinI am using pybind11 with custom signatures (not the pybind11 auto-generated ones) to build the python binding from C++.
simple example
```cpp .def(py::initAt first I, thought it was related to my overloaded
__init__()
, but it seems to be happening anytime I specify themembers
option.As a workaround I can use
but it breaks when I use