Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docstring clarifications #9877

Merged
merged 6 commits into from Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 21 additions & 22 deletions sphinx/addnodes.py
Expand Up @@ -2,7 +2,7 @@
sphinx.addnodes
~~~~~~~~~~~~~~~

Additional docutils nodes.
Document tree nodes that Sphinx defines on top of those in Docutils.

:copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
Expand Down Expand Up @@ -120,7 +120,7 @@ def extract_original_messages(self) -> List[str]:
#############################################################

class _desc_classes_injector(nodes.Element, not_smartquotable):
"""Helper base class for injecting a fixes list of classes.
"""Helper base class for injecting a fixed list of classes.

Use as the first base class.
"""
Expand Down Expand Up @@ -391,7 +391,7 @@ class index(nodes.Invisible, nodes.Inline, nodes.TextElement):


class centered(nodes.Part, nodes.TextElement):
"""Deprecated."""
"""This node is deprecated."""


class acks(nodes.Element):
Expand Down Expand Up @@ -456,13 +456,18 @@ class pending_xref(nodes.Inline, nodes.Element):


class pending_xref_condition(nodes.Inline, nodes.TextElement):
"""Node for cross-references that are used to choose appropriate
content of the reference by conditions on the resolving phase.
"""Node representing a potential way to create a cross-reference and the
condition in which this way should be used.

When the :py:class:`pending_xref` node contains one or more
**pending_xref_condition** nodes, the cross-reference resolver
should choose the content of the reference using defined conditions
in ``condition`` attribute of each pending_xref_condition nodes::
This node is only allowed to be placed under a :py:class:`pending_xref`
node. A **pending_xref** node must contain either no **pending_xref_condition**
nodes or it must only contains **pending_xref_condition** nodes.

The cross-reference resolver will replace a :py:class:`pending_xref` which
contains **pending_xref_condition** nodes by the content of exactly one of
those **pending_xref_condition** nodes' content. It uses the **condition**
attribute to decide which **pending_xref_condition** node's content to
use. For example, let us consider how the cross-reference resolver acts on::

<pending_xref refdomain="py" reftarget="io.StringIO ...>
<pending_xref_condition condition="resolved">
Expand All @@ -472,32 +477,26 @@ class pending_xref_condition(nodes.Inline, nodes.TextElement):
<literal>
io.StringIO

After the processing of cross-reference resolver, one of the content node
under pending_xref_condition node is chosen by its condition and to be
removed all of pending_xref_condition nodes::
If the cross-reference resolver successfully resolves the cross-reference,
then it rewrites the **pending_xref** as::

# When resolved the cross-reference successfully
<reference>
<literal>
StringIO

# When resolution is failed
Otherwise, if the cross-reference resolution failed, it rewrites the
**pending_xref** as::

<reference>
<literal>
io.StringIO

.. note:: This node is only allowed to be placed under pending_xref node.
It is not allows to place it under other nodes. In addition,
pending_xref node must contain only pending_xref_condition
nodes if it contains one or more pending_xref_condition nodes.

The pending_xref_condition node should have **condition** attribute.
The **pending_xref_condition** node should have **condition** attribute.
Domains can be store their individual conditions into the attribute to
filter contents on resolving phase. As a reserved condition name,
``condition="*"`` is used for the fallback of resolution failure.
Additionally, as a recommended condition name, ``condition="resolved"``
is used for the representation of resolstion success in the intersphinx
module.
represents a resolution success in the intersphinx module.

.. versionadded:: 4.0
"""
Expand Down
79 changes: 47 additions & 32 deletions sphinx/application.py
Expand Up @@ -632,8 +632,9 @@ def add_directive(self, name: str, cls: Type[Directive], override: bool = False)

:param name: The name of the directive
:param cls: A directive class
:param override: If true, install the directive forcedly even if another directive
:param override: If false, do not install it if another directive
is already installed as the same name
If true, unconditionally install the directive.

For example, a custom directive named ``my-directive`` would be added
like this:
Expand Down Expand Up @@ -680,8 +681,9 @@ def add_role(self, name: str, role: Any, override: bool = False) -> None:

:param name: The name of role
:param role: A role function
:param override: If true, install the role forcedly even if another role is already
installed as the same name
:param override: If false, do not install it if another role
is already installed as the same name
If true, unconditionally install the role.

For more details about role functions, see `the Docutils docs
<https://docutils.sourceforge.io/docs/howto/rst-roles.html>`__ .
Expand All @@ -701,8 +703,9 @@ def add_generic_role(self, name: str, nodeclass: Any, override: bool = False) ->
Register a Docutils role that does nothing but wrap its contents in the
node given by *nodeclass*.

If *override* is True, the given *nodeclass* is forcedly installed even if
a role named as *name* is already installed.
:param override: If false, do not install it if another role
is already installed as the same name
If true, unconditionally install the role.

.. versionadded:: 0.6
.. versionchanged:: 1.8
Expand All @@ -721,8 +724,9 @@ def add_domain(self, domain: Type[Domain], override: bool = False) -> None:
"""Register a domain.

:param domain: A domain class
:param override: If true, install the domain forcedly even if another domain
:param override: If false, do not install it if another domain
is already installed as the same name
If true, unconditionally install the domain.

.. versionadded:: 1.0
.. versionchanged:: 1.8
Expand All @@ -740,8 +744,9 @@ def add_directive_to_domain(self, domain: str, name: str,
:param domain: The name of target domain
:param name: A name of directive
:param cls: A directive class
:param override: If true, install the directive forcedly even if another directive
:param override: If false, do not install it if another directive
is already installed as the same name
If true, unconditionally install the directive.

.. versionadded:: 1.0
.. versionchanged:: 1.8
Expand All @@ -759,8 +764,9 @@ def add_role_to_domain(self, domain: str, name: str, role: Union[RoleFunction, X
:param domain: The name of the target domain
:param name: The name of the role
:param role: The role function
:param override: If true, install the role forcedly even if another role is already
installed as the same name
:param override: If false, do not install it if another role
is already installed as the same name
If true, unconditionally install the role.

.. versionadded:: 1.0
.. versionchanged:: 1.8
Expand All @@ -776,8 +782,9 @@ def add_index_to_domain(self, domain: str, index: Type[Index], override: bool =

:param domain: The name of the target domain
:param index: The index class
:param override: If true, install the index forcedly even if another index is
already installed as the same name
:param override: If false, do not install it if another index
is already installed as the same name
If true, unconditionally install the index.

.. versionadded:: 1.0
.. versionchanged:: 1.8
Expand Down Expand Up @@ -881,8 +888,10 @@ def add_crossref_type(self, directivename: str, rolename: str, indextemplate: st
(Of course, the element following the ``topic`` directive needn't be a
section.)

If *override* is True, the given crossref_type is forcedly installed even if
a crossref_type having the same name is already installed.

:param override: If false, do not install it if another cross-reference type
is already installed as the same name
If true, unconditionally install the cross-reference type.

.. versionchanged:: 1.8
Add *override* keyword.
Expand Down Expand Up @@ -937,17 +946,19 @@ def add_post_transform(self, transform: Type[Transform]) -> None:
"""
self.registry.add_post_transform(transform)

def add_js_file(self, filename: str, priority: int = 500, **kwargs: Any) -> None:
def add_js_file(self, filename: Optional[str], priority: int = 500, **kwargs: Any) -> None:
"""Register a JavaScript file to include in the HTML output.

Add *filename* to the list of JavaScript files that the default HTML
template will include in order of *priority* (ascending). The filename
must be relative to the HTML static path , or a full URI with scheme.
If the priority of the JavaScript file is the same as others, the JavaScript
files will be included in order of registration. If the keyword
argument ``body`` is given, its value will be added between the
``<script>`` tags. Extra keyword arguments are included as attributes of
the ``<script>`` tag.
:param filename: The name of a file that the default HTML
template will include. It must be relative to the HTML
static path, or a full URI with scheme.
:param priority: Files are included in ascending order of priority. If
multiple JavaScript files have the same priority,
those files will be included in order of registration.
:param kwargs: If the keyword argument ``body`` is given, its value will
be added between the ``<script>`` tags.
Extra keyword arguments are included as attributes of
the ``<script>`` tag.

Example::

Expand Down Expand Up @@ -991,12 +1002,14 @@ def add_js_file(self, filename: str, priority: int = 500, **kwargs: Any) -> None
def add_css_file(self, filename: str, priority: int = 500, **kwargs: Any) -> None:
"""Register a stylesheet to include in the HTML output.

Add *filename* to the list of CSS files that the default HTML template
will include in order of *priority* (ascending). The filename must be
relative to the HTML static path, or a full URI with scheme. If the
priority of the CSS file is the same as others, the CSS files will be
included in order of registration. The keyword arguments are also
accepted for attributes of ``<link>`` tag.
:param filename: The name of a CSS file that the default HTML
template will include. It must be relative to the HTML
static path, or a full URI with scheme.
:param priority: Files are included in ascending order of priority. If
multiple CSS files have the same priority,
those files will be included in order of registration.
:param kwargs: The keyword arguments are also accepted for attributes of
``<link>`` tag.

Example::

Expand Down Expand Up @@ -1163,8 +1176,9 @@ def add_source_suffix(self, suffix: str, filetype: str, override: bool = False)
Same as :confval:`source_suffix`. The users can override this
using the config setting.

If *override* is True, the given *suffix* is forcedly installed even if
the same suffix is already installed.
:param override: If false, do not install it the same suffix
is already installed.
If true, unconditionally install the suffix.

.. versionadded:: 1.8
"""
Expand All @@ -1173,8 +1187,9 @@ def add_source_suffix(self, suffix: str, filetype: str, override: bool = False)
def add_source_parser(self, parser: Type[Parser], override: bool = False) -> None:
"""Register a parser class.

If *override* is True, the given *parser* is forcedly installed even if
a parser for the same suffix is already installed.
:param override: If false, do not install it if another parser
is already installed for the same suffix.
If true, unconditionally install the parser.

.. versionadded:: 1.4
.. versionchanged:: 1.8
Expand Down
2 changes: 1 addition & 1 deletion sphinx/builders/latex/transforms.py
Expand Up @@ -38,7 +38,7 @@ def apply(self, **kwargs: Any) -> None:


class SubstitutionDefinitionsRemover(SphinxPostTransform):
"""Remove ``substitution_definition node from doctrees."""
"""Remove ``substitution_definition`` node from doctrees."""
AA-Turner marked this conversation as resolved.
Show resolved Hide resolved

# should be invoked after Substitutions process
default_priority = Substitutions.default_priority + 1
Expand Down
6 changes: 3 additions & 3 deletions sphinx/domains/std.py
Expand Up @@ -493,12 +493,12 @@ def run(self) -> List[Node]:
lines = nl_escape_re.sub('', self.arguments[0]).split('\n')

productionGroup = ""
i = 0
first_rule_seen = False
for rule in lines:
if i == 0 and ':' not in rule:
if not first_rule_seen and ':' not in rule:
productionGroup = rule.strip()
continue
i += 1
first_rule_seen = True
try:
name, tokens = rule.split(':', 1)
except ValueError:
Expand Down
9 changes: 8 additions & 1 deletion sphinx/extension.py
Expand Up @@ -42,7 +42,14 @@ def __init__(self, name: str, module: Any, **kwargs: Any) -> None:


def verify_needs_extensions(app: "Sphinx", config: Config) -> None:
"""Verify the required Sphinx extensions are loaded."""
"""Check that extensions mentioned in :confval:`needs_extensions` satisfy the version
requirement, and warn if an extension is not loaded.

Warns if an extension in :confval:`needs_extension` is not loaded.

:raises VersionRequirementError: if the version of an extension in
:confval:`needs_extension` is unknown or older than the required version.
"""
if config.needs_extensions is None:
return

Expand Down