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 Test for a parameter with difficult type
(mostly for python) (mostly for python)
:type a: Shape :type a: :py:class:`Shape`
:param a: Very strange param :param a: Very strange param
""" """
) )

View file

@ -18,6 +18,8 @@
#include <vector> #include <vector>
#include <iostream> #include <iostream>
#include "swigmod.h"
// define static tables, they are filled in PyDocConverter's constructor // define static tables, they are filled in PyDocConverter's constructor
PyDocConverter::TagHandlersMap PyDocConverter::tagHandlers; PyDocConverter::TagHandlersMap PyDocConverter::tagHandlers;
std::map<std::string, std::string> PyDocConverter::sectionTitles; 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")); ParmList *plist = CopyParmList(Getattr(currentNode, "parms"));
for (Parm *p = plist; p;p = nextSibling(p)) { for (Parm *p = plist; p;p = nextSibling(p)) {
if (Char (Getattr(p, "name")) != param) String* pname = Getattr(p, "name");
if (Char (pname) != param)
continue; continue;
String *s = Swig_typemap_lookup("doctype", p, Getattr(p, "name"), 0); String *s = Swig_typemap_lookup("doctype", p, pname, 0);
if (!s) if (!s)
s = SwigType_str(Getattr(p, "type"), ""); s = SwigType_str(Getattr(p, "type"), "");
// In Python C++ namespaces are flattened, so remove all but last component if (Language::classLookup(s)) {
// of the name. // In Python C++ namespaces are flattened, so remove all but last component
String * const last = Swig_scopename_last(s); // 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); Delete(s);
break; break;
} }