网页
综合
更新时间 2026-11-17 02:47:44
The Python Domain — Sphinx documentation
自动蜘蛛
www.sphinx-doc.org
正文约 4317 字
Added in version 1.0.
The Python domain (name py) provides the following directives for module declarations:
This directive marks the beginning of the description of a module (or package submodule, in which case the name should be fully qualified, including the package name). A description of the module such as the docstring can be placed in the body of the directive.
This directive will also cause an entry in the global module index.
Changed in version 5.2: Module directives support body content.
Indicate platforms which the module is available (if it is available on all platforms, the option should be omitted). The keys are short identifiers; examples that are in use include “IRIX”, “Mac”, “Windows” and “Unix”. It is important to use a key which has already been used when applicable.
Consist of one sentence describing the module’s purpose – it is currently only used in the Global Module Index.
Mark a module as deprecated; it will be designated as such in various locations then.
This directive tells Sphinx that the classes, functions etc. documented from here are in the given module (like py:module), but it will not create index entries, an entry in the Global Module Index, or a link target for py:mod. This is helpful in situations where documentation for things in a module is spread over multiple files or sections – one location has the py:module directive, the others only py:currentmodule.
The following directives are provided for module and class contents:
Describes a module-level function. The signature should include the parameters, together with optional type parameters, as given in the Python function definition, see Python Signatures. For example:
For methods you should use py:method.
The description normally includes information about the parameters required and how they are used (especially whether mutable objects passed as parameters are modified), side effects, and possible exceptions.
This information can (in any py directive) optionally be given in a structured form, see Info field lists.
Indicate the function is an async function.
Added in version 2.1.
Describe the location where the object is defined if the object is imported from other modules
Added in version 4.0.
Ensures that the function’s arguments will be emitted on a single logical line, overriding python_maximum_signature_line_length and maximum_signature_line_length.
Added in version 7.1.
Ensure that the function’s type parameters are emitted on a single logical line, overriding python_maximum_signature_line_length and maximum_signature_line_length.
Added in version 7.1.
Describes global data in a module, including both variables and values used as “defined constants.” Consider using py:type for type aliases instead and py:attribute for class variables and instance attributes.
This will be parsed as a Python expression for cross-referencing the type annotation. As such, the argument to :type: should be a valid annotation expression.
The valid syntax for the :type: directive option differs from the syntax for the :type: info field. The :type: directive option does not understand reStructuredText markup or the or or of keywords, meaning unions must use | and sequences must use square brackets, and roles such as :ref:`...` cannot be used.
Added in version 2.4.
Added in version 2.4.
Describe the location where the object is defined if the object is imported from other modules
Added in version 4.0.
Describes an exception class. The signature can, but need not include parentheses with constructor arguments, or may optionally include type parameters (see PEP 695).
Indicate the class is a final class.
Added in version 3.1.
See py:class:single-line-parameter-list.
Added in version 7.1.
See py:class:single-line-type-parameter-list.
Added in version 7.1.
Describes a class. The signature can optionally include type parameters (see PEP 695) or parentheses with parameters which will be shown as the constructor arguments. See also Python Signatures.
Methods and attributes belonging to the class should be placed in this directive’s body. If they are placed outside, the supplied name should contain the class name so that cross-references still work. Example:
The first way is the preferred one.
Indicate that the class is an abstract base class. This produces the following output:
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。