Re: Python docstrings on C structs
"Seth G" <[email protected]>
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <[email protected]> |
Hi all,
It was an issue with the placement of the %feature("docstring") - I had been trying to add them to .i files long after the structs were declared in the header files.
Moving these to the header files allowed property docstrings to be set.
Code can be seen as part of https://github.com/mapserver/mapserver/pull/6071
Seth
--
web:http://geographika.co.uk
twitter: @geographika
On Mon, May 18, 2020, at 11:57 PM, Seth G wrote:
> Hi all,
>
> Is it possible to set Python docstrings on C structs with SWIG?
>
> For example if I have:
>
> struct classObj {
> int debug;
> };
>
> SWIG creates the following Python wrapper code:
>
> debug = property(_mapscript.classObj_debug_get, _mapscript.classObj_debug_set)
>
> I'd like to be able to set the doc parameter here so it can be used for
> generating Sphinx docs:
>
> debug = property(_mapscript.classObj_debug_get,
> _mapscript.classObj_debug_set, doc="This is my docstring")
>
> I am currently doing this by adding Python code (which works fine):
>
> %extend classObj {
> %pythoncode %{
>
> debug.__doc__ = "This is my docstring"
>
> However, should I be able to use a docstring directive to accomplish
> the same output? E.g.
>
> %feature("docstring", "This is my docstring") classObj.debug ; //
> throws an error, but not sure how to apply this to the struct attribute
>
> The example in Examples/python/docstrings/example.i uses C++:
>
> %feature("docstring") Foo::bar "No comment"
>
> I'm unsure if I'm using the wrong syntax, if the %feature is in the
> wrong location, or it is not currently possible in SWIG 4.0.
>
> Any clarifications much appreciated,
>
> Regards,
>
> Seth
>
> --
> web:http://geographika.co.uk
> twitter: @geographika