Python docstrings on C structs

"Seth G" <[email protected]>
Newsgroups gmane.comp.programming.swig
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.