Fields are used to describe specific properties of a documented object. For example, fields can be used to define the parameters and return value of a function; the instance variables of a class; and the author of a module. Each field consists of a tag, an optional argument, and a body.
Each docstring markup langauge marks fields differently. The following table shows the basic fields syntax for each markup language. For more information, see the definition of field syntax for each markup language.
Epytext | reStructuredText | Javadoc |
---|---|---|
@tag: body ...@tag arg: body ... |
:tag: body ...:tag arg: body ... |
@tag body ...@tag arg body ... |
Definition of epytext fields |
Definition of reStructuredText fields |
Definition of Javadoc fields |
The following table lists the fields that epydoc currently recognizes. Field tags are written using epytext markup; if you are using a different markup language, then you should adjust the markup accordingly.
Functions and Methods (function or method docstrings) | |
---|---|
@param p: ... |
A description of the parameter p for a
function or method. It may appear in the class docstring to describe
a costructor parameter: mostly useful for C extensions. |
@type p: ... |
The expected type for the parameter.
p . |
@return: ... | The return value for a function or method. |
@rtype: ... | The type of the return value for a function or method. |
@keyword p: ... |
A description of the keyword parameter p .
It may appear in the class docstring to describe
a costructor keyword parameter. |
@raise e: ... |
A description of the circumstances under which a function or
method raises exception e .
It may appear in the class docstring to describe
an exception that can be raised by the costructor. |
Variables (module, class or variable docstrings) | |
@ivar v: ... |
A description of the class instance variable
v . |
@cvar v: ... |
A description of the static class variable
v . |
@var v: ... |
A description of the module variable
v . |
@type v: ... |
The type of the variable
v . |
Properties (property docstrings) | |
@type: ... | The type of the property. |
Grouping and Sorting (module, class, function, or method docstrings) | |
@group g: c1,...,cn |
Organizes a set of related children of a module or class into a group.
g is the name of the group; and
c1,...,cn are the names
of the children in the group. To define multiple groups, use
multiple group fields. |
@sort: c1,...,cn |
Specifies the sort order for the children of a module or class.
c1,...,cn are the names
of the children, in the order in which they should appear. Any
children that are not included in this list will appear after
the children from this list, in alphabetical order.
|
Related Topics | |
@see: ... |
A description of a related topic. see fields
typically use documentation crossreference links or external
hyperlinks that link to the related topic. |
Notes and Warnings | |
@note: ... |
A note about an object. Multiple
note fields may be used to list separate
notes. |
@attention: ... |
An important note about an object. Multiple
attention fields may be used to list separate
notes. |
@bug: ... |
A description of a bug in an object.
Multiple bug fields may be used to report separate
bugs. |
@warning: ... |
A warning about an object. Multiple
warning fields may be used to report separate
warnings. |
Status | |
@version: ... | The current version of an object. |
@todo [ver]: ... | A planned
change to an object. If the optional argument ver
is given, then it specifies the version for which the change will be
made. Multiple todo fields may be used if multiple
changes are planned. |
@deprecated: ... | Indicates that an object is deprecated. The body of the field describe the reason why the object is deprecated. |
@since: ... | The date or version when an object was first introduced. |
@status: ... | The current status of an object. |
@change: ... | A change log entry for this object. |
@permission: ... | The object access permission, for systems such Zope/Plone supporting this concept. It may be used more than once to specify multiple permissions. |
Formal Conditions | |
@requires: ... |
A requirement for using an object. Multiple requires
fields may be used if an object has multiple
requirements. |
@precondition: ... |
A condition that must be true before an object is used. Multiple
precondition fields may be used if an object has
multiple preconditions. |
@postcondition: ... |
A condition that is guaranteed to be true after an object is used.
Multiple postcondition fields may be used if an
object has multiple postconditions. |
@invariant: ... |
A condition which should always be true for an object. Multiple
invariant fields may be used if an object has
multiple invariants. |
Bibliographic Information | |
@author: ... | The author(s) of an
object. Multiple author
fields may be used if an object has multiple authors. |
@organization: ... | The organization that created or maintains an object. |
@copyright: ... | The copyright information for an object. |
@license: ... | The licensing information for an object. |
@contact: ... | Contact information
for the author or maintainer of a module, class, function, or
method. Multiple contact fields may be used if an
object has multiple contacts. |
Summarization | |
@summary: ... | A summary description for an object. This description overrides the default summary (which is constructed from the first sentence of the object's description). |
@param
fields should be used to document any
explicit parameter (including the keyword parameter).
@keyword
fields should only be used for non-explicit
keyword parameters:
def
plant
(seed, *tools, **options):"""
@param seed:
The seed that should be planted.@param tools:
Tools that should be used to plant the seed.@param options:
Any extra options for the planting.@keyword dig_deep:
Plant the seed deep under ground.@keyword soak:
Soak the seed before planting it."""
[...]
For the @group
and @sort
tags,
asterisks (*
) can be used to specify multiple children at
once. An asterisk in a child name will match any substring:
class
widget
(size, weight, age):"""
@group Tools:
zip, zap, *_tool@group Accessors:
get_*@sort:
get_*, set_*, unpack_*, cut"""
[...]
Since the @type
field allows for arbitrary text,
it does not automatically create a crossreference link to the
specified type, and is not written in fixed-width font by default. If
you want to create a crossreference link to the type, or to write the
type in a fixed-width font, then you must use inline markup:
def
ponder
(person, time):"""
@param person:
Who should think.@type person:
L{Person} or L{Animal}@param time:
How long they should think.@type time:
C{int} or C{float}"""
[...]
Normally the fields are written in the docstring of the documented objects: this allows you to add fields to modules, classes, function, properties. Where a docstring is not allowed, usually alternative options do exist.
Python variables don't support docstrings. The variable can be described
in the module or class where it is defined using the tags @var
,
@ivar
, @cvar
; but this only allows for a textual
description: no further metadata can be added to the variable (except for the
type, using the @type
tag.
Epydoc supports variable docstrings: if a variable
assignment statement is immediately followed by a bare string literal,
then that assignment is treated as a docstring for that variable. In
classes, variable assignments at the class definition level are
considered class variables; and assignments to instance variables in
the constructor (__init__
) are considered instance variables:
>>>
class
A:...
x = 22...
"""Docstring for class variable A.x"""
...
...
def
__init__
(self, a):...
self.y = a...
"""Docstring for instance variable A.y
Variables may also be documented using comment docstrings.
If a variable assignment is immediately preceeded by a comment whose
lines begin with the special marker "#:
", or is
followed on the same line by such a comment, then it is treated as a
docstring for that variable:
>>>
#: docstring for x
...
x = 22>>>
x = 22#: docstring for x
A common Python idiom is to create instance variables settings their
default value in the class instead of the constructor (hopefully if the default
is immutable...). To avoid Epydoc to interpret such variable as a class
variable, you can describe it using the tag @ivar
in the
context of a variable docstring:
>>>
class
B:...
y = 42...
"""@ivar: This is an instance variable."""
Notice that variable docstrings are only available for documentation when the source code is available for parsing: it is not possible to retrieve variable docstrings from introspection informations only.
In a C extension module, extension classes cannot have a docstring attached
to the __init__
function; consequently it is not possible to
document parameters and exceptions raised by the class constructor. To overcome
this shortcoming, the tags @param
, @keyword
,
@type
, @exception
are allowed to appear in the class
docstring to refer to constructor parameters.
Several fields have "synonyms," or alternate tags. The following table lists all field synonyms. Field tags are written using epytext markup; if you are using a different markup language, then you should adjust the markup accordingly.
|
|
Some module variables are commonly used as module metadata. Epydoc can use the value provided by these variables as alternate form for tags. The following table lists the recognized variables and the tag they replace. Customized metadata variables can be added using the method described in Adding New Fields.
Tag | Variable |
---|---|
@deprecated |
__deprecated__ |
@version |
__version__ |
@date |
__date__ |
@author @authors |
__author__ __authors__ |
@contact |
__contact__ |
@copyright |
__copyright__ |
@license |
__license__ |
New fields can be defined for the docstrings in a module using the
special @newfield
tag (or its synonym,
@deffield
). This tag has the following syntax:
@newfield tag: label [, plural]
Where tag
is the new tag that's being defined;
label
is a string that will be used to mark this
field in the generated output; and plural
is the
plural form of label
, if different.
It will also be possibile to use the module variable
__tag__
to set the value for the newly defined tag.
The following
example illustrates how the @newfield
can be used:
Docstring Input | Rendered Output |
---|---|
""" @newfield corpus: Corpus, Corpora """ |
Corpora:
|
Note: The module-level variable
__extra_epydoc_fields__
is deprecated; use
@newfield
instead.
For the most part, fields are treated identically, regardless of what markup language is used to encode them. However, there are a few minor differences, which are intended to accomodate existing standards for each markup language. In particular:
@see
fields. For more information about these differences, read the subsections below.
In reStructuredText, a single field can be used to encode the
documentation for a group of related items. For example, a single
:Parameters:
field is often used to describe all of the
parameters for a function or method:
def
fox_speed
(size, weight, age):""" Return the maximum speed for a fox.
[...]:Parameters:
- `size`: The size of the fox (in meters) - `weight`: The weight of the fox (in stones) - `age`: The age of the fox (in years) """
Epydoc will automatically extract information about each parameter from this list. These consolidated fields may be written using either a bulleted list or a definition list. If a consolidated field is written as a bulleted list, then each list item must begin with the field's argument, marked as interpreted text, and followed by a colon or dash. If a consolidated field is written as a definition list, then each definition item's term should contain the field's argument, (it is not mandatory for it being marked as interpreted text). The term classifier, if present, is used to specify the associated type. The following example shows the use of a definition list to define a consolidated field. (Note that docutils requires a space before and after the ":" used to mark classifiers.)
def
fox_speed
(size, weight, age):""" Return the maximum speed for a fox.
[...]:Parameters:
size The size of the fox (in meters) weight : float The weight of the fox (in stones) age : int The age of the fox (in years) """
The following consolidated fields are currently supported by epydoc:
|
|
For compatibility with Javadoc, every @see
field is
assumed to contain a single crossreference link, unless its body
is quoted, or it starts with an HTML tag. See the
Javadoc reference manual for more information about how the
@see
field is encoded in Javadoc.
Because Javadoc does not mark end of the optional argument, field arguments must contain exactly one word. Thus, multi-word arguments are not available in Javadoc. In particular, all group names must be single words.
Home | Installing Epydoc | Using Epydoc | Epytext |