<p>不是一个完整的答案,或多或少是一个起点:</p>
<p><code>autodoc</code>将自动指令转换为python指令。
因此可以使用autodoc事件来获取翻译后的python指令。在</p>
<p>例如,如果您有以下<code>mymodule.py</code>:</p>
<pre><code>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This is my module.
"""
def my_test_func(a, b=1):
"""This is my test function"""
return a + b
class MyClass(object):
"""This is my class"""
def __init__(x, y='test'):
"""The init of my class"""
self.x = float(x)
self.y = y
def my_method(self, z):
"""This is my method.
:param z: a number
:type z: float, int
:returns: the sum of self.x and z
:rtype: float
"""
return self.x + z
</code></pre>
<p><code>sphinx-apidoc</code>将创建</p>
^{pr2}$
<p>以下扩展名(或<code>conf.py</code>的加法):</p>
^{3}$
<p>会给你:</p>
<pre><code>My module documentation
-
.. py:module:: mymodule
This is my module.
.. py:class:: mymodule.MyClass(x, y='test')
This is my class
.. py:method:: mymodule.MyClass.my_method(z)
This is my method.
:param z: a number
:type z: float, int
:returns: the sum of self.x and z
:rtype: float
.. py:function:: mymodule.my_test_func(a, b=1)
This is my test function
</code></pre>
<p>但是,由于<code>autodoc</code>不发出任何事件,因此当翻译完成时,autodoc所做的进一步处理必须适应这里的docstring。在</p>