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.
These tags can be used to specify attributes of parameters and return value of function and methods. These tags are usually put in the the docstring of the function to be documented.
Note
constructor parameters
In C extension modules, 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 also allowed to appear in the class docstring. In this case they refer to constructor parameters.
@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. """ #[...]
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} """ #[...]
These tags are usually put in a module or class docstring. If the sources can be parsed by Epydoc it is also possible to document the variable in their own docstrings: see variable docstrings
Epydoc considers class variables the ones defined directly defined in the class body. 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...).
If you want to force Epydoc to classify as instance variable one whose default value is set at class level, 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."""
The @type tag can be attached toa property docstring to specify its type.
These tags can be used to present groups of related items in a logical way. They apply to modules and classes docstrings.
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 """ #[...]
Note
group markers
It is also possible to group set of related items enclosing them into special comment starting with the group markers '#{' and '#}' The group title can be specified after the opening group marker. Example:
#{ Database access functions def read(id): #[...] def store(item): #[...] def delete(id): #[...] # groups can't be nested, so a closing marker is not required here. #{ Web publish functions def get(request): #[...] def post(request): #[...] #}
A description of a bug in an object. Multiple bug fields may be used to report separate bugs.
Note
If any @bug field is used, the HTML writer will generate a the page bug-index.html, containing links to all the items tagged with the field.
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.
Note
If any @todo field is used, the HTML writer will generate a the page todo-index.html, containing links to all the items tagged with the field.
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.
Name | Synonims |
---|---|
@param p: ... | @parameter p: ...
@arg p: ...
@argument p: ...
|
@return: ... | @returns: ... |
@rtype: ... | @returntype: ... |
@raise e: ... | @raises e: ...
@except e: ...
@exception e: ...
|
@keyword p: ... | @kwarg p: ...
@kwparam p: ...
|
@ivar v: ... | @ivariable v: ... |
@cvar v: ... | @cvariable v: ... |
@var v: ... | @variable v: ... |
@see: ... | @seealso: ... |
@warning: ... | @warn: ... |
@requires: ... | @require: ...
@requirement: ...
|
@precondition: ... | @precond: ... |
@postcondition: ... | @postcond: ... |
@organization: ... | @org: ... |
@copyright: ... | @(c): ... |
@change: ... | @changed: ... |
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 |
---|---|
@author | __author__ |
@authors | __authors__ |
@contact | __contact__ |
@copyright | __copyright__ |
@license | __license__ |
@deprecated | __deprecated__ |
@date | __date__ |
@version | __version__ |
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.
New fields can be defined in any Python module. If they are defined in a package, it will be possible to use the newly defined tag from every package submodule.
Each new field will also define a metadata variable which can be used to set the field value instead of the tag. For example, if a revision tag has been defined with:
@newfield revision: Revision
then it will be possible to set a value for the field using a module variable:
__revision__ = "1234"
The following example illustrates how the @newfield can be used: Docstring Input Rendered Output
Docstring Input | Rendered Output |
---|---|
""" @newfield corpus: Corpus, Corpora """ def example(): """ @corpus: Bob's wordlist. @corpus: The British National Corpus. """ [...] |
Corpora:
|
Note
The module-level variable __extra_epydoc_fields__ is deprecated; use @newfield instead.
Home | Installing Epydoc | Using Epydoc | Epytext |