Document the return type when translating Doxygen @return to Python.
In addition to translating the comment itself, also document the type of the object returned. This is consistent with generating not only :param: but also :type: for the parameters documented using @param.
This commit is contained in:
parent
1f826b0925
commit
6aa9cd37a5
4 changed files with 49 additions and 22 deletions
|
|
@ -13,6 +13,7 @@ commentVerifier.check(doxygen_basic_translate.function.__doc__,
|
||||||
|
|
||||||
Author: Some author
|
Author: Some author
|
||||||
|
|
||||||
|
:rtype: int
|
||||||
:return: Some number
|
:return: Some number
|
||||||
|
|
||||||
See also: function2
|
See also: function2
|
||||||
|
|
@ -86,6 +87,7 @@ commentVerifier.check(doxygen_basic_translate.Atan2.__doc__,
|
||||||
:param y: Vertical coordinate.
|
:param y: Vertical coordinate.
|
||||||
:type x: float
|
:type x: float
|
||||||
:param x: Horizontal coordinate.
|
:param x: Horizontal coordinate.
|
||||||
|
:rtype: float
|
||||||
:return: Arc tangent of ``y/x``.
|
:return: Arc tangent of ``y/x``.
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -263,10 +263,13 @@ r"""
|
||||||
|
|
||||||
Another remarks section
|
Another remarks section
|
||||||
|
|
||||||
|
:rtype: int
|
||||||
:return: Whatever
|
:return: Whatever
|
||||||
|
|
||||||
|
:rtype: int
|
||||||
:return: it
|
:return: it
|
||||||
|
|
||||||
|
:rtype: int
|
||||||
:return: may return
|
:return: may return
|
||||||
|
|
||||||
""")
|
""")
|
||||||
|
|
|
||||||
|
|
@ -99,10 +99,13 @@ r"""
|
||||||
|
|
||||||
Another remarks section
|
Another remarks section
|
||||||
|
|
||||||
|
:rtype: int
|
||||||
:return: Whatever
|
:return: Whatever
|
||||||
|
|
||||||
|
:rtype: int
|
||||||
:return: it
|
:return: it
|
||||||
|
|
||||||
|
:rtype: int
|
||||||
:return: may return
|
:return: may return
|
||||||
|
|
||||||
See also: someOtherMethod
|
See also: someOtherMethod
|
||||||
|
|
|
||||||
|
|
@ -334,6 +334,38 @@ PyDocConverter::PyDocConverter(int flags) :
|
||||||
fillStaticTables();
|
fillStaticTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the type as it should appear in the output documentation.
|
||||||
|
static
|
||||||
|
std::string getPyDocType(Node* n, const_String_or_char_ptr lname = "")
|
||||||
|
{
|
||||||
|
std::string type;
|
||||||
|
|
||||||
|
String *s = Swig_typemap_lookup("doctype", n, lname, 0);
|
||||||
|
if (!s)
|
||||||
|
s = SwigType_str(Getattr(n, "type"), "");
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
Delete(s);
|
||||||
|
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
std::string PyDocConverter::getParamType(std::string param)
|
std::string PyDocConverter::getParamType(std::string param)
|
||||||
{
|
{
|
||||||
std::string type;
|
std::string type;
|
||||||
|
|
@ -344,28 +376,7 @@ std::string PyDocConverter::getParamType(std::string param)
|
||||||
if (Char (pname) != param)
|
if (Char (pname) != param)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
String *s = Swig_typemap_lookup("doctype", p, pname, 0);
|
type = getPyDocType(p, pname);
|
||||||
if (!s)
|
|
||||||
s = SwigType_str(Getattr(p, "type"), "");
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
Delete(s);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Delete(plist);
|
Delete(plist);
|
||||||
|
|
@ -619,6 +630,14 @@ void PyDocConverter::handleTagReturn(DoxygenEntity &tag,
|
||||||
{
|
{
|
||||||
IndentGuard indent(translatedComment, m_indent);
|
IndentGuard indent(translatedComment, m_indent);
|
||||||
|
|
||||||
|
const std::string pytype = getPyDocType(currentNode);
|
||||||
|
if (!pytype.empty()) {
|
||||||
|
translatedComment += ":rtype: ";
|
||||||
|
translatedComment += pytype;
|
||||||
|
translatedComment += "\n";
|
||||||
|
translatedComment += indent.getFirstLineIndent();
|
||||||
|
}
|
||||||
|
|
||||||
translatedComment += ":return: ";
|
translatedComment += ":return: ";
|
||||||
handleParagraph(tag, translatedComment);
|
handleParagraph(tag, translatedComment);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue