Make Python parameters types hyperlinks in the doc strings.

It is very useful to be able to click on the parameter types in a function
documentation to go to this parameter description, so always use hyperlink
markup for the parameters of class types, even if not all of them are
necessarily documented -- Sphinx doesn't seem to complain about links to
unknown classes.
This commit is contained in:
Vadim Zeitlin 2014-08-05 16:21:09 +02:00
commit bb01e06a6a
2 changed files with 22 additions and 8 deletions

View file

@ -71,7 +71,7 @@ commentVerifier.check(doxygen_basic_translate.function7.__doc__,
"""
Test for a parameter with difficult type
(mostly for python)
:type a: Shape
:type a: :py:class:`Shape`
:param a: Very strange param
"""
)

View file

@ -18,6 +18,8 @@
#include <vector>
#include <iostream>
#include "swigmod.h"
// define static tables, they are filled in PyDocConverter's constructor
PyDocConverter::TagHandlersMap PyDocConverter::tagHandlers;
std::map<std::string, std::string> PyDocConverter::sectionTitles;
@ -309,19 +311,31 @@ std::string PyDocConverter::getParamType(std::string param)
ParmList *plist = CopyParmList(Getattr(currentNode, "parms"));
for (Parm *p = plist; p;p = nextSibling(p)) {
if (Char (Getattr(p, "name")) != param)
String* pname = Getattr(p, "name");
if (Char (pname) != param)
continue;
String *s = Swig_typemap_lookup("doctype", p, Getattr(p, "name"), 0);
String *s = Swig_typemap_lookup("doctype", p, pname, 0);
if (!s)
s = SwigType_str(Getattr(p, "type"), "");
// In Python C++ namespaces are flattened, so remove all but last component
// of the name.
String * const last = Swig_scopename_last(s);
if (Language::classLookup(s)) {
// In Python C++ namespaces are flattened, so remove all but last component
// of the name.
String * const last = Swig_scopename_last(s);
// We are not actually sure whether it's a documented class or not, but
// there doesn't seem to be any harm in making it a reference if it isn't,
// while there is a lot of benefit in having a hyperlink if it is.
type = ":py:class:`";
type += Char (last);
type += "`";
Delete(last);
} else {
type = Char(s);
}
type = Char (s);
Delete(last);
Delete(s);
break;
}