Skip to content

Commit 6508121

Browse files
Arthur-Milchiorjakobandersentk0miyaAA-Turner
authored
Docstring clarifications (#9877)
Co-authored-by: Jakob Lykke Andersen <[email protected]> Co-authored-by: Takeshi KOMIYA <[email protected]> Co-authored-by: Adam Turner <[email protected]>
1 parent b842cab commit 6508121

File tree

5 files changed

+85
-65
lines changed

5 files changed

+85
-65
lines changed

sphinx/addnodes.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Additional docutils nodes."""
1+
"""Document tree nodes that Sphinx defines on top of those in Docutils."""
22

33
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence
44

@@ -119,7 +119,7 @@ def extract_original_messages(self) -> List[str]:
119119
#############################################################
120120

121121
class _desc_classes_injector(nodes.Element, not_smartquotable):
122-
"""Helper base class for injecting a fixes list of classes.
122+
"""Helper base class for injecting a fixed list of classes.
123123
124124
Use as the first base class.
125125
"""
@@ -390,7 +390,7 @@ class index(nodes.Invisible, nodes.Inline, nodes.TextElement):
390390

391391

392392
class centered(nodes.Part, nodes.TextElement):
393-
"""Deprecated."""
393+
"""This node is deprecated."""
394394

395395

396396
class acks(nodes.Element):
@@ -455,13 +455,18 @@ class pending_xref(nodes.Inline, nodes.Element):
455455

456456

457457
class pending_xref_condition(nodes.Inline, nodes.TextElement):
458-
"""Node for cross-references that are used to choose appropriate
459-
content of the reference by conditions on the resolving phase.
458+
"""Node representing a potential way to create a cross-reference and the
459+
condition in which this way should be used.
460460
461-
When the :py:class:`pending_xref` node contains one or more
462-
**pending_xref_condition** nodes, the cross-reference resolver
463-
should choose the content of the reference using defined conditions
464-
in ``condition`` attribute of each pending_xref_condition nodes::
461+
This node is only allowed to be placed under a :py:class:`pending_xref`
462+
node. A **pending_xref** node must contain either no **pending_xref_condition**
463+
nodes or it must only contains **pending_xref_condition** nodes.
464+
465+
The cross-reference resolver will replace a :py:class:`pending_xref` which
466+
contains **pending_xref_condition** nodes by the content of exactly one of
467+
those **pending_xref_condition** nodes' content. It uses the **condition**
468+
attribute to decide which **pending_xref_condition** node's content to
469+
use. For example, let us consider how the cross-reference resolver acts on::
465470
466471
<pending_xref refdomain="py" reftarget="io.StringIO ...>
467472
<pending_xref_condition condition="resolved">
@@ -471,32 +476,26 @@ class pending_xref_condition(nodes.Inline, nodes.TextElement):
471476
<literal>
472477
io.StringIO
473478
474-
After the processing of cross-reference resolver, one of the content node
475-
under pending_xref_condition node is chosen by its condition and to be
476-
removed all of pending_xref_condition nodes::
479+
If the cross-reference resolver successfully resolves the cross-reference,
480+
then it rewrites the **pending_xref** as::
477481
478-
# When resolved the cross-reference successfully
479482
<reference>
480483
<literal>
481484
StringIO
482485
483-
# When resolution is failed
486+
Otherwise, if the cross-reference resolution failed, it rewrites the
487+
**pending_xref** as::
488+
484489
<reference>
485490
<literal>
486491
io.StringIO
487492
488-
.. note:: This node is only allowed to be placed under pending_xref node.
489-
It is not allows to place it under other nodes. In addition,
490-
pending_xref node must contain only pending_xref_condition
491-
nodes if it contains one or more pending_xref_condition nodes.
492-
493-
The pending_xref_condition node should have **condition** attribute.
493+
The **pending_xref_condition** node should have **condition** attribute.
494494
Domains can be store their individual conditions into the attribute to
495495
filter contents on resolving phase. As a reserved condition name,
496496
``condition="*"`` is used for the fallback of resolution failure.
497497
Additionally, as a recommended condition name, ``condition="resolved"``
498-
is used for the representation of resolstion success in the intersphinx
499-
module.
498+
represents a resolution success in the intersphinx module.
500499
501500
.. versionadded:: 4.0
502501
"""

sphinx/application.py

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,9 @@ def add_directive(self, name: str, cls: Type[Directive], override: bool = False)
639639
640640
:param name: The name of the directive
641641
:param cls: A directive class
642-
:param override: If true, install the directive forcedly even if another directive
642+
:param override: If false, do not install it if another directive
643643
is already installed as the same name
644+
If true, unconditionally install the directive.
644645
645646
For example, a custom directive named ``my-directive`` would be added
646647
like this:
@@ -687,8 +688,9 @@ def add_role(self, name: str, role: Any, override: bool = False) -> None:
687688
688689
:param name: The name of role
689690
:param role: A role function
690-
:param override: If true, install the role forcedly even if another role is already
691-
installed as the same name
691+
:param override: If false, do not install it if another role
692+
is already installed as the same name
693+
If true, unconditionally install the role.
692694
693695
For more details about role functions, see `the Docutils docs
694696
<https://docutils.sourceforge.io/docs/howto/rst-roles.html>`__ .
@@ -708,8 +710,9 @@ def add_generic_role(self, name: str, nodeclass: Any, override: bool = False) ->
708710
Register a Docutils role that does nothing but wrap its contents in the
709711
node given by *nodeclass*.
710712
711-
If *override* is True, the given *nodeclass* is forcedly installed even if
712-
a role named as *name* is already installed.
713+
:param override: If false, do not install it if another role
714+
is already installed as the same name
715+
If true, unconditionally install the role.
713716
714717
.. versionadded:: 0.6
715718
.. versionchanged:: 1.8
@@ -728,8 +731,9 @@ def add_domain(self, domain: Type[Domain], override: bool = False) -> None:
728731
"""Register a domain.
729732
730733
:param domain: A domain class
731-
:param override: If true, install the domain forcedly even if another domain
734+
:param override: If false, do not install it if another domain
732735
is already installed as the same name
736+
If true, unconditionally install the domain.
733737
734738
.. versionadded:: 1.0
735739
.. versionchanged:: 1.8
@@ -747,8 +751,9 @@ def add_directive_to_domain(self, domain: str, name: str,
747751
:param domain: The name of target domain
748752
:param name: A name of directive
749753
:param cls: A directive class
750-
:param override: If true, install the directive forcedly even if another directive
754+
:param override: If false, do not install it if another directive
751755
is already installed as the same name
756+
If true, unconditionally install the directive.
752757
753758
.. versionadded:: 1.0
754759
.. versionchanged:: 1.8
@@ -766,8 +771,9 @@ def add_role_to_domain(self, domain: str, name: str, role: Union[RoleFunction, X
766771
:param domain: The name of the target domain
767772
:param name: The name of the role
768773
:param role: The role function
769-
:param override: If true, install the role forcedly even if another role is already
770-
installed as the same name
774+
:param override: If false, do not install it if another role
775+
is already installed as the same name
776+
If true, unconditionally install the role.
771777
772778
.. versionadded:: 1.0
773779
.. versionchanged:: 1.8
@@ -783,8 +789,9 @@ def add_index_to_domain(self, domain: str, index: Type[Index], override: bool =
783789
784790
:param domain: The name of the target domain
785791
:param index: The index class
786-
:param override: If true, install the index forcedly even if another index is
787-
already installed as the same name
792+
:param override: If false, do not install it if another index
793+
is already installed as the same name
794+
If true, unconditionally install the index.
788795
789796
.. versionadded:: 1.0
790797
.. versionchanged:: 1.8
@@ -889,8 +896,10 @@ def add_crossref_type(self, directivename: str, rolename: str, indextemplate: st
889896
(Of course, the element following the ``topic`` directive needn't be a
890897
section.)
891898
892-
If *override* is True, the given crossref_type is forcedly installed even if
893-
a crossref_type having the same name is already installed.
899+
900+
:param override: If false, do not install it if another cross-reference type
901+
is already installed as the same name
902+
If true, unconditionally install the cross-reference type.
894903
895904
.. versionchanged:: 1.8
896905
Add *override* keyword.
@@ -949,20 +958,22 @@ def add_js_file(self, filename: Optional[str], priority: int = 500,
949958
loading_method: Optional[str] = None, **kwargs: Any) -> None:
950959
"""Register a JavaScript file to include in the HTML output.
951960
952-
:param filename: The filename of the JavaScript file. It must be relative to the HTML
953-
static path, a full URI with scheme, or ``None`` value. The ``None``
954-
value is used to create inline ``<script>`` tag. See the description
955-
of *kwargs* below.
956-
:param priority: The priority to determine the order of ``<script>`` tag for
957-
JavaScript files. See list of "prority range for JavaScript
958-
files" below. If the priority of the JavaScript files it the same
959-
as others, the JavaScript files will be loaded in order of
960-
registration.
961-
:param loading_method: The loading method of the JavaScript file. ``'async'`` or
962-
``'defer'`` is allowed.
963-
:param kwargs: Extra keyword arguments are included as attributes of the ``<script>``
964-
tag. A special keyword argument ``body`` is given, its value will be
965-
added between the ``<script>`` tag.
961+
:param filename: The name of a JavaScript file that the default HTML
962+
template will include. It must be relative to the HTML
963+
static path, or a full URI with scheme, or ``None`` .
964+
The ``None`` value is used to create an inline
965+
``<script>`` tag. See the description of *kwargs*
966+
below.
967+
:param priority: Files are included in ascending order of priority. If
968+
multiple JavaScript files have the same priority,
969+
those files will be included in order of registration.
970+
See list of "prority range for JavaScript files" below.
971+
:param loading_method: The loading method for the JavaScript file.
972+
Either ``'async'`` or ``'defer'`` are allowed.
973+
:param kwargs: Extra keyword arguments are included as attributes of the
974+
``<script>`` tag. If the special keyword argument
975+
``body`` is given, its value will be added as the content
976+
of the ``<script>`` tag.
966977
967978
Example::
968979
@@ -1015,14 +1026,15 @@ def add_js_file(self, filename: Optional[str], priority: int = 500,
10151026
def add_css_file(self, filename: str, priority: int = 500, **kwargs: Any) -> None:
10161027
"""Register a stylesheet to include in the HTML output.
10171028
1018-
:param filename: The filename of the CSS file. It must be relative to the HTML
1029+
:param filename: The name of a CSS file that the default HTML
1030+
template will include. It must be relative to the HTML
10191031
static path, or a full URI with scheme.
1020-
:param priority: The priority to determine the order of ``<link>`` tag for the
1021-
CSS files. See list of "prority range for CSS files" below.
1022-
If the priority of the CSS files it the same as others, the
1023-
CSS files will be loaded in order of registration.
1024-
:param kwargs: Extra keyword arguments are included as attributes of the ``<link>``
1025-
tag.
1032+
:param priority: Files are included in ascending order of priority. If
1033+
multiple CSS files have the same priority,
1034+
those files will be included in order of registration.
1035+
See list of "prority range for CSS files" below.
1036+
:param kwargs: Extra keyword arguments are included as attributes of the
1037+
``<link>`` tag.
10261038
10271039
Example::
10281040
@@ -1191,8 +1203,9 @@ def add_source_suffix(self, suffix: str, filetype: str, override: bool = False)
11911203
Same as :confval:`source_suffix`. The users can override this
11921204
using the config setting.
11931205
1194-
If *override* is True, the given *suffix* is forcedly installed even if
1195-
the same suffix is already installed.
1206+
:param override: If false, do not install it the same suffix
1207+
is already installed.
1208+
If true, unconditionally install the suffix.
11961209
11971210
.. versionadded:: 1.8
11981211
"""
@@ -1201,8 +1214,9 @@ def add_source_suffix(self, suffix: str, filetype: str, override: bool = False)
12011214
def add_source_parser(self, parser: Type[Parser], override: bool = False) -> None:
12021215
"""Register a parser class.
12031216
1204-
If *override* is True, the given *parser* is forcedly installed even if
1205-
a parser for the same suffix is already installed.
1217+
:param override: If false, do not install it if another parser
1218+
is already installed for the same suffix.
1219+
If true, unconditionally install the parser.
12061220
12071221
.. versionadded:: 1.4
12081222
.. versionchanged:: 1.8

sphinx/builders/latex/transforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def apply(self, **kwargs: Any) -> None:
3030

3131

3232
class SubstitutionDefinitionsRemover(SphinxPostTransform):
33-
"""Remove ``substitution_definition node from doctrees."""
33+
"""Remove ``substitution_definition`` nodes from doctrees."""
3434

3535
# should be invoked after Substitutions process
3636
default_priority = Substitutions.default_priority + 1

sphinx/domains/std.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,12 +493,12 @@ def run(self) -> List[Node]:
493493
lines = nl_escape_re.sub('', self.arguments[0]).split('\n')
494494

495495
productionGroup = ""
496-
i = 0
496+
first_rule_seen = False
497497
for rule in lines:
498-
if i == 0 and ':' not in rule:
498+
if not first_rule_seen and ':' not in rule:
499499
productionGroup = rule.strip()
500500
continue
501-
i += 1
501+
first_rule_seen = True
502502
try:
503503
name, tokens = rule.split(':', 1)
504504
except ValueError:

sphinx/extension.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@ def __init__(self, name: str, module: Any, **kwargs: Any) -> None:
3434

3535

3636
def verify_needs_extensions(app: "Sphinx", config: Config) -> None:
37-
"""Verify the required Sphinx extensions are loaded."""
37+
"""Check that extensions mentioned in :confval:`needs_extensions` satisfy the version
38+
requirement, and warn if an extension is not loaded.
39+
40+
Warns if an extension in :confval:`needs_extension` is not loaded.
41+
42+
:raises VersionRequirementError: if the version of an extension in
43+
:confval:`needs_extension` is unknown or older than the required version.
44+
"""
3845
if config.needs_extensions is None:
3946
return
4047

0 commit comments

Comments
 (0)