我正在将一些C#代码转换为Python 3,其中包括通常在原始C#代码中以XML摘要形式编写的文档。
这些摘要引用了类名作为<see cref="ClassName"/>
元素或<paramref name="fileName"/>
元素来引用参数,当将其转换为HTML时创建可点击的链接。我想知道在我使用的Python ReST文档字符串格式中是否有类似的功能。
例如,让我们看看这个C#方法文档:
/// <summary>
/// Reads and returns a <see cref="DummyFile"/> instance from the file with the
/// given <paramref name="fileName"/>.
/// </summary>
/// <param name="fileName">The name of the file to read the data from.</param>
/// <returns>The read <see cref="DummyFile"/> instance.</returns>
public DummyFile LoadDummyFile(string fileName)
{
// Do some dummy file work.
}
在Python中,我会将它转换为:
"""
Reads and returns a DummyFile instance from the file with the given file_name.
:param file_name: The name of the file to read the data from.
:param str file_name: The name of the file to read the data from.
:return: The read DummyFile instance.
:rtype: DummyFile
"""
def load_dummy_file(file_name: str) -> DummyFile
# Do some dummy file work.
(有人使用:rtype
吗?)
如您所见,我只是将类名和参数名输入为纯文本,不知道在创建Web文档时是否有这种特殊语法可以创建可点击链接。
在ReST docstrings中创建此类引用是否可能,如果可以,它们的语法(希望不要比C#长)是什么?