Replies: 2 comments 2 replies
-
Hi @gobater, thanks for the detailed report. Looking at Griffe's code, I can already tell you that a stubs docstring is only used if the actual object does not have a docstring itself, explaining why setting docstrings to NULL in your C code helps. Are you able to set constructors' docstrings to NULL too, so that the one from stubs is used? We can consider always using stubs docstrings, but I'll have to evaluate whether it could be a breaking change. About attribute values being shown as their representation ( |
Beta Was this translation helpful? Give feedback.
-
Hi @pawamoy , Unfortunately it's not possible to set/remove the docstring of the constructor in CPython. The constructor and some other dunder methods always have a weird meaning-less default docstring :( About Another issue I am facing is the "labels" field. When inspecting, because the parent is a class, the attributes get the label "class" instead of "instance-attribute" which shall be correct in my case. I've seen where all this in the code happens, so I will try to hack something and provide a PR. I guess it could make sense to customize the priority of docstrings for c-extensions and stubs... since as mentioned before, there is no chance to do it in C for the constructor |
Beta Was this translation helpful? Give feedback.
-
I have developed a python extension module in "C" (https://docs.python.org/3/c-api/index.html) and I am facing several issues when trying to generate some documentation with mkdocsstrings-python and griffe.
Several issues:
1. Constructor
The C API does not allow to specify a docstring for the
__init__
slot (constructor) and therefore they always have a default signature:I try to overcome that limitation using a stub (and triggering griffe with '-B') for my module but somehow griffe does not produce the output I expect.
The stub file contains following definition
see here some command line DEBUG output
The output JSON, for the constructor provides the following information:
Searching for the word "Constructor" in the JSON output of griffe produces 0 results.
How can I overcome this problem?
2. Properties / Attributes
In C extension modules, the structure "PyMemberDef" (https://docs.python.org/3/c-api/structures.html#c.PyMemberDef) can be used to describe attributes (read-write or read-only). See details of CPython: https://docs.python.org/3/library/inspect.html#inspect.ismemberdescriptor
My C code contains the following:
JSON output
The output rendered with mkdocstrings-python
As you can see, value shows
repr()
of the object which looks weird.As an alternative, I've tried to provide an empty (NULL) docstring in the C extension. In that case, griffe takes the docstring from the stub, in two different forms, as an attribute or as a property, but still tries to show the
repr
of the object...Similar occurs when using PyGetSetDef (https://docs.python.org/3/c-api/structures.html#c.PyGetSetDef). See details of CPython: https://docs.python.org/3/library/inspect.html#inspect.isgetsetdescriptor
Note that here, the type of the attribute is read from the stub
Tuple[float,float]
but also therepr
is shown...Am I doing something wrong? Is it possible to overcome any of the two problems described above? I could try to provide a 'simple' C module for testing if needed.
I guess all this might be related due to the usage of "-x" (dynamic inspection). I guess using "-X" could be an alternative, but then I will be forced to document everything in the stub and maintaining in parallel the docstrings in the C extension module
Beta Was this translation helpful? Give feedback.
All reactions