I would like to add python docstrings to my classes and methods that are defined in C++,
so the documentation is accessible through the __doc__ attribute.
Is this possible somehow?
Thanks in advance,
Melven
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As far as I know this is not possible, because the __doc__ string is part of the Python class type and I think I remember that I did not manage to overload it (because the underlying code requires the __doc__ string to be present when the wrapper class is registered).
But you are welcome to investigate this, it might be possible to pass the doc string into PythonQt::registerClass and to get it into the derived PythonQtClassWrapper struct which is created for each registered wrapper class.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
and try to set result.type.tp_doc to your docstring. Make sure that the string you pass does not get deleted, Python expects a const char* and does not do a copy.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I did a short test with a hard-coded string, but it didn't show up in python.
So I think I need to understand whats happening there and have a short look at the python documentation first…
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I would like to add python docstrings to my classes and methods that are defined in C++,
so the documentation is accessible through the __doc__ attribute.
Is this possible somehow?
Thanks in advance,
Melven
As far as I know this is not possible, because the __doc__ string is part of the Python class type and I think I remember that I did not manage to overload it (because the underlying code requires the __doc__ string to be present when the wrapper class is registered).
But you are welcome to investigate this, it might be possible to pass the doc string into PythonQt::registerClass and to get it into the derived PythonQtClassWrapper struct which is created for each registered wrapper class.
Look for
PythonQtPrivate::createNewPythonQtClassWrapper
and try to set result.type.tp_doc to your docstring. Make sure that the string you pass does not get deleted, Python expects a const char* and does not do a copy.
Thanks, that should probably help!
I did a short test with a hard-coded string, but it didn't show up in python.
So I think I need to understand whats happening there and have a short look at the python documentation first…
I have played a bit around with the docstrings and finally had some success:
For the
the
member didn't work for me, but it worked using the additionally supplied
that already contains the
.
For the docstring of class-methods (e.g. public slots), there was already a function that returned
.
In order to add doc-strings to a class a decorator-class must be used (e.g.
).
I think my solution is still improvable:
* I call qt_metacall without setting/checking arguments correctly
* the decorators have the form
for class documentation
for method documentation.
Here is a full diff (that can be applied with patch -p1 -i <docString.patch>)
(I'm sorry for the bad indentation, there seems to be no preview-feature in this forum…)
Another idea for the syntax of the decorator functions:
For the class-documentation:
For the class-method documentation:
This would prevent problems with underscores in the class-/method-names.
Additionally I don't know how my code works together with overloaded public slot methods…