[英]How do I document “sub-classes” using sphinx and autodoc?
假设我有一个文件example.py,内容如下:
class Body(object):
"""Representation of a geometric body."""
def __init__(self):
self.surface = Surface(self)
class Surface(object):
"""Representation of a geometric surface."""
def __init__(self, body):
self.body = body
def get_surface_area(self):
""" Calculate surface area of the body """
print 4
mybody = Body()
mybody.surface.get_surface_area()
当我做
.. automodule:: example
:members:
我将所有两个类和函数记录下来。 但是,我该如何指出类的预期用法,即mybody.surface.get_surface_area()
并且还具有正确的链接?
我不完全确定这是否是您想要的,但是这是关于如何记录课程的建议:
class Body(object):
"""Representation of a geometric body.
:ivar surface: a :class:`example.Surface` instance
Usage example:
>>> mybody = Body()
>>> mybody.surface.get_surface_area()
>>> 4
Another way of doing it:
>>> mybody = Body()
>>> mysurface = Surface(mybody)
>>> mysurface.get_surface_area()
>>> 4
"""
def __init__(self):
self.surface = Surface(self)
class Surface(object):
"""Representation of a geometric surface.
:ivar body: The supplied :class:`example.Body` instance
"""
def __init__(self, body):
self.body = body
def get_surface_area(self):
""" Calculate surface area of the body """
print 4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.