Sphinx 7.1.2__py3-none-any.whl → 7.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of Sphinx might be problematic. Click here for more details.

Files changed (313) hide show
  1. sphinx/__init__.py +6 -6
  2. sphinx/__main__.py +3 -1
  3. sphinx/addnodes.py +35 -22
  4. sphinx/application.py +40 -38
  5. sphinx/builders/__init__.py +16 -12
  6. sphinx/builders/_epub_base.py +15 -11
  7. sphinx/builders/changes.py +6 -4
  8. sphinx/builders/dirhtml.py +4 -2
  9. sphinx/builders/dummy.py +6 -4
  10. sphinx/builders/epub3.py +16 -8
  11. sphinx/builders/gettext.py +40 -43
  12. sphinx/builders/html/__init__.py +166 -196
  13. sphinx/builders/html/_assets.py +116 -0
  14. sphinx/builders/html/transforms.py +4 -2
  15. sphinx/builders/latex/__init__.py +12 -7
  16. sphinx/builders/latex/theming.py +5 -2
  17. sphinx/builders/latex/transforms.py +6 -3
  18. sphinx/builders/linkcheck.py +18 -11
  19. sphinx/builders/manpage.py +6 -4
  20. sphinx/builders/singlehtml.py +16 -9
  21. sphinx/builders/texinfo.py +11 -6
  22. sphinx/builders/text.py +8 -3
  23. sphinx/builders/xml.py +9 -4
  24. sphinx/cmd/build.py +27 -14
  25. sphinx/cmd/make_mode.py +13 -4
  26. sphinx/cmd/quickstart.py +13 -4
  27. sphinx/config.py +17 -14
  28. sphinx/deprecation.py +4 -2
  29. sphinx/directives/__init__.py +44 -12
  30. sphinx/directives/code.py +5 -4
  31. sphinx/directives/other.py +92 -44
  32. sphinx/directives/patches.py +1 -1
  33. sphinx/domains/__init__.py +11 -8
  34. sphinx/domains/c.py +67 -57
  35. sphinx/domains/changeset.py +3 -2
  36. sphinx/domains/citation.py +2 -1
  37. sphinx/domains/cpp.py +136 -93
  38. sphinx/domains/index.py +9 -5
  39. sphinx/domains/javascript.py +32 -19
  40. sphinx/domains/math.py +5 -3
  41. sphinx/domains/python.py +69 -57
  42. sphinx/domains/rst.py +20 -11
  43. sphinx/domains/std.py +21 -15
  44. sphinx/environment/__init__.py +97 -65
  45. sphinx/environment/adapters/indexentries.py +13 -10
  46. sphinx/environment/adapters/toctree.py +485 -308
  47. sphinx/environment/collectors/__init__.py +3 -4
  48. sphinx/environment/collectors/asset.py +10 -4
  49. sphinx/environment/collectors/dependencies.py +7 -4
  50. sphinx/environment/collectors/metadata.py +7 -5
  51. sphinx/environment/collectors/title.py +5 -3
  52. sphinx/environment/collectors/toctree.py +13 -8
  53. sphinx/errors.py +1 -1
  54. sphinx/events.py +5 -5
  55. sphinx/ext/apidoc.py +49 -27
  56. sphinx/ext/autodoc/__init__.py +179 -161
  57. sphinx/ext/autodoc/directive.py +10 -6
  58. sphinx/ext/autodoc/importer.py +22 -13
  59. sphinx/ext/autodoc/mock.py +4 -1
  60. sphinx/ext/autodoc/preserve_defaults.py +80 -12
  61. sphinx/ext/autodoc/type_comment.py +14 -10
  62. sphinx/ext/autodoc/typehints.py +7 -3
  63. sphinx/ext/autosectionlabel.py +6 -3
  64. sphinx/ext/autosummary/__init__.py +21 -15
  65. sphinx/ext/autosummary/generate.py +176 -126
  66. sphinx/ext/coverage.py +93 -8
  67. sphinx/ext/doctest.py +28 -17
  68. sphinx/ext/duration.py +19 -17
  69. sphinx/ext/extlinks.py +11 -6
  70. sphinx/ext/githubpages.py +8 -7
  71. sphinx/ext/graphviz.py +61 -17
  72. sphinx/ext/ifconfig.py +7 -4
  73. sphinx/ext/imgconverter.py +4 -2
  74. sphinx/ext/imgmath.py +29 -23
  75. sphinx/ext/inheritance_diagram.py +41 -27
  76. sphinx/ext/intersphinx.py +45 -38
  77. sphinx/ext/linkcode.py +8 -5
  78. sphinx/ext/mathjax.py +13 -9
  79. sphinx/ext/napoleon/__init__.py +3 -3
  80. sphinx/ext/napoleon/docstring.py +40 -31
  81. sphinx/ext/todo.py +10 -7
  82. sphinx/ext/viewcode.py +46 -25
  83. sphinx/extension.py +1 -1
  84. sphinx/highlighting.py +20 -12
  85. sphinx/io.py +5 -4
  86. sphinx/jinja2glue.py +24 -19
  87. sphinx/locale/__init__.py +8 -2
  88. sphinx/locale/ar/LC_MESSAGES/sphinx.mo +0 -0
  89. sphinx/locale/ar/LC_MESSAGES/sphinx.po +756 -740
  90. sphinx/locale/bg/LC_MESSAGES/sphinx.mo +0 -0
  91. sphinx/locale/bg/LC_MESSAGES/sphinx.po +754 -738
  92. sphinx/locale/bn/LC_MESSAGES/sphinx.mo +0 -0
  93. sphinx/locale/bn/LC_MESSAGES/sphinx.po +755 -739
  94. sphinx/locale/ca/LC_MESSAGES/sphinx.mo +0 -0
  95. sphinx/locale/ca/LC_MESSAGES/sphinx.po +768 -752
  96. sphinx/locale/cak/LC_MESSAGES/sphinx.mo +0 -0
  97. sphinx/locale/cak/LC_MESSAGES/sphinx.po +754 -738
  98. sphinx/locale/cs/LC_MESSAGES/sphinx.mo +0 -0
  99. sphinx/locale/cs/LC_MESSAGES/sphinx.po +758 -742
  100. sphinx/locale/cy/LC_MESSAGES/sphinx.mo +0 -0
  101. sphinx/locale/cy/LC_MESSAGES/sphinx.po +759 -743
  102. sphinx/locale/da/LC_MESSAGES/sphinx.mo +0 -0
  103. sphinx/locale/da/LC_MESSAGES/sphinx.po +760 -744
  104. sphinx/locale/de/LC_MESSAGES/sphinx.mo +0 -0
  105. sphinx/locale/de/LC_MESSAGES/sphinx.po +759 -743
  106. sphinx/locale/de_DE/LC_MESSAGES/sphinx.mo +0 -0
  107. sphinx/locale/de_DE/LC_MESSAGES/sphinx.po +754 -738
  108. sphinx/locale/el/LC_MESSAGES/sphinx.mo +0 -0
  109. sphinx/locale/el/LC_MESSAGES/sphinx.po +763 -747
  110. sphinx/locale/en_DE/LC_MESSAGES/sphinx.mo +0 -0
  111. sphinx/locale/en_DE/LC_MESSAGES/sphinx.po +754 -738
  112. sphinx/locale/en_FR/LC_MESSAGES/sphinx.mo +0 -0
  113. sphinx/locale/en_FR/LC_MESSAGES/sphinx.po +754 -738
  114. sphinx/locale/en_GB/LC_MESSAGES/sphinx.mo +0 -0
  115. sphinx/locale/en_GB/LC_MESSAGES/sphinx.po +768 -752
  116. sphinx/locale/en_HK/LC_MESSAGES/sphinx.mo +0 -0
  117. sphinx/locale/en_HK/LC_MESSAGES/sphinx.po +754 -738
  118. sphinx/locale/eo/LC_MESSAGES/sphinx.mo +0 -0
  119. sphinx/locale/eo/LC_MESSAGES/sphinx.po +754 -738
  120. sphinx/locale/es/LC_MESSAGES/sphinx.mo +0 -0
  121. sphinx/locale/es/LC_MESSAGES/sphinx.po +767 -751
  122. sphinx/locale/es_CO/LC_MESSAGES/sphinx.mo +0 -0
  123. sphinx/locale/es_CO/LC_MESSAGES/sphinx.po +754 -738
  124. sphinx/locale/et/LC_MESSAGES/sphinx.mo +0 -0
  125. sphinx/locale/et/LC_MESSAGES/sphinx.po +762 -746
  126. sphinx/locale/eu/LC_MESSAGES/sphinx.mo +0 -0
  127. sphinx/locale/eu/LC_MESSAGES/sphinx.po +755 -739
  128. sphinx/locale/fa/LC_MESSAGES/sphinx.mo +0 -0
  129. sphinx/locale/fa/LC_MESSAGES/sphinx.po +766 -750
  130. sphinx/locale/fi/LC_MESSAGES/sphinx.mo +0 -0
  131. sphinx/locale/fi/LC_MESSAGES/sphinx.po +754 -738
  132. sphinx/locale/fr/LC_MESSAGES/sphinx.mo +0 -0
  133. sphinx/locale/fr/LC_MESSAGES/sphinx.po +768 -752
  134. sphinx/locale/fr_FR/LC_MESSAGES/sphinx.mo +0 -0
  135. sphinx/locale/fr_FR/LC_MESSAGES/sphinx.po +754 -738
  136. sphinx/locale/gl/LC_MESSAGES/sphinx.js +60 -0
  137. sphinx/locale/gl/LC_MESSAGES/sphinx.mo +0 -0
  138. sphinx/locale/gl/LC_MESSAGES/sphinx.po +3695 -0
  139. sphinx/locale/he/LC_MESSAGES/sphinx.mo +0 -0
  140. sphinx/locale/he/LC_MESSAGES/sphinx.po +755 -739
  141. sphinx/locale/hi/LC_MESSAGES/sphinx.mo +0 -0
  142. sphinx/locale/hi/LC_MESSAGES/sphinx.po +763 -747
  143. sphinx/locale/hi_IN/LC_MESSAGES/sphinx.mo +0 -0
  144. sphinx/locale/hi_IN/LC_MESSAGES/sphinx.po +754 -738
  145. sphinx/locale/hr/LC_MESSAGES/sphinx.mo +0 -0
  146. sphinx/locale/hr/LC_MESSAGES/sphinx.po +760 -744
  147. sphinx/locale/hu/LC_MESSAGES/sphinx.mo +0 -0
  148. sphinx/locale/hu/LC_MESSAGES/sphinx.po +759 -743
  149. sphinx/locale/id/LC_MESSAGES/sphinx.mo +0 -0
  150. sphinx/locale/id/LC_MESSAGES/sphinx.po +765 -749
  151. sphinx/locale/is/LC_MESSAGES/sphinx.mo +0 -0
  152. sphinx/locale/is/LC_MESSAGES/sphinx.po +760 -744
  153. sphinx/locale/it/LC_MESSAGES/sphinx.mo +0 -0
  154. sphinx/locale/it/LC_MESSAGES/sphinx.po +760 -744
  155. sphinx/locale/ja/LC_MESSAGES/sphinx.mo +0 -0
  156. sphinx/locale/ja/LC_MESSAGES/sphinx.po +767 -751
  157. sphinx/locale/ka/LC_MESSAGES/sphinx.mo +0 -0
  158. sphinx/locale/ka/LC_MESSAGES/sphinx.po +759 -743
  159. sphinx/locale/ko/LC_MESSAGES/sphinx.mo +0 -0
  160. sphinx/locale/ko/LC_MESSAGES/sphinx.po +767 -751
  161. sphinx/locale/lt/LC_MESSAGES/sphinx.mo +0 -0
  162. sphinx/locale/lt/LC_MESSAGES/sphinx.po +755 -739
  163. sphinx/locale/lv/LC_MESSAGES/sphinx.mo +0 -0
  164. sphinx/locale/lv/LC_MESSAGES/sphinx.po +755 -739
  165. sphinx/locale/mk/LC_MESSAGES/sphinx.mo +0 -0
  166. sphinx/locale/mk/LC_MESSAGES/sphinx.po +754 -738
  167. sphinx/locale/nb_NO/LC_MESSAGES/sphinx.mo +0 -0
  168. sphinx/locale/nb_NO/LC_MESSAGES/sphinx.po +755 -739
  169. sphinx/locale/ne/LC_MESSAGES/sphinx.mo +0 -0
  170. sphinx/locale/ne/LC_MESSAGES/sphinx.po +755 -739
  171. sphinx/locale/nl/LC_MESSAGES/sphinx.mo +0 -0
  172. sphinx/locale/nl/LC_MESSAGES/sphinx.po +760 -744
  173. sphinx/locale/pl/LC_MESSAGES/sphinx.mo +0 -0
  174. sphinx/locale/pl/LC_MESSAGES/sphinx.po +762 -745
  175. sphinx/locale/pt/LC_MESSAGES/sphinx.mo +0 -0
  176. sphinx/locale/pt/LC_MESSAGES/sphinx.po +754 -738
  177. sphinx/locale/pt_BR/LC_MESSAGES/sphinx.mo +0 -0
  178. sphinx/locale/pt_BR/LC_MESSAGES/sphinx.po +768 -752
  179. sphinx/locale/pt_PT/LC_MESSAGES/sphinx.mo +0 -0
  180. sphinx/locale/pt_PT/LC_MESSAGES/sphinx.po +755 -739
  181. sphinx/locale/ro/LC_MESSAGES/sphinx.mo +0 -0
  182. sphinx/locale/ro/LC_MESSAGES/sphinx.po +759 -743
  183. sphinx/locale/ru/LC_MESSAGES/sphinx.mo +0 -0
  184. sphinx/locale/ru/LC_MESSAGES/sphinx.po +760 -744
  185. sphinx/locale/si/LC_MESSAGES/sphinx.mo +0 -0
  186. sphinx/locale/si/LC_MESSAGES/sphinx.po +754 -738
  187. sphinx/locale/sk/LC_MESSAGES/sphinx.mo +0 -0
  188. sphinx/locale/sk/LC_MESSAGES/sphinx.po +765 -749
  189. sphinx/locale/sl/LC_MESSAGES/sphinx.mo +0 -0
  190. sphinx/locale/sl/LC_MESSAGES/sphinx.po +755 -739
  191. sphinx/locale/sphinx.pot +748 -740
  192. sphinx/locale/sq/LC_MESSAGES/sphinx.mo +0 -0
  193. sphinx/locale/sq/LC_MESSAGES/sphinx.po +768 -752
  194. sphinx/locale/sr/LC_MESSAGES/sphinx.mo +0 -0
  195. sphinx/locale/sr/LC_MESSAGES/sphinx.po +754 -738
  196. sphinx/locale/sr@latin/LC_MESSAGES/sphinx.mo +0 -0
  197. sphinx/locale/sr@latin/LC_MESSAGES/sphinx.po +754 -738
  198. sphinx/locale/sr_RS/LC_MESSAGES/sphinx.mo +0 -0
  199. sphinx/locale/sr_RS/LC_MESSAGES/sphinx.po +754 -738
  200. sphinx/locale/sv/LC_MESSAGES/sphinx.mo +0 -0
  201. sphinx/locale/sv/LC_MESSAGES/sphinx.po +755 -739
  202. sphinx/locale/ta/LC_MESSAGES/sphinx.mo +0 -0
  203. sphinx/locale/ta/LC_MESSAGES/sphinx.po +754 -738
  204. sphinx/locale/te/LC_MESSAGES/sphinx.mo +0 -0
  205. sphinx/locale/te/LC_MESSAGES/sphinx.po +754 -738
  206. sphinx/locale/tr/LC_MESSAGES/sphinx.mo +0 -0
  207. sphinx/locale/tr/LC_MESSAGES/sphinx.po +763 -747
  208. sphinx/locale/uk_UA/LC_MESSAGES/sphinx.mo +0 -0
  209. sphinx/locale/uk_UA/LC_MESSAGES/sphinx.po +760 -749
  210. sphinx/locale/ur/LC_MESSAGES/sphinx.mo +0 -0
  211. sphinx/locale/ur/LC_MESSAGES/sphinx.po +759 -748
  212. sphinx/locale/vi/LC_MESSAGES/sphinx.mo +0 -0
  213. sphinx/locale/vi/LC_MESSAGES/sphinx.po +754 -738
  214. sphinx/locale/yue/LC_MESSAGES/sphinx.mo +0 -0
  215. sphinx/locale/yue/LC_MESSAGES/sphinx.po +754 -738
  216. sphinx/locale/zh_CN/LC_MESSAGES/sphinx.mo +0 -0
  217. sphinx/locale/zh_CN/LC_MESSAGES/sphinx.po +768 -752
  218. sphinx/locale/zh_HK/LC_MESSAGES/sphinx.mo +0 -0
  219. sphinx/locale/zh_HK/LC_MESSAGES/sphinx.po +754 -738
  220. sphinx/locale/zh_TW/LC_MESSAGES/sphinx.mo +0 -0
  221. sphinx/locale/zh_TW/LC_MESSAGES/sphinx.po +767 -751
  222. sphinx/locale/zh_TW.Big5/LC_MESSAGES/sphinx.mo +0 -0
  223. sphinx/locale/zh_TW.Big5/LC_MESSAGES/sphinx.po +754 -738
  224. sphinx/parsers.py +5 -4
  225. sphinx/project.py +52 -34
  226. sphinx/pycode/__init__.py +2 -1
  227. sphinx/pycode/ast.py +7 -13
  228. sphinx/pycode/parser.py +42 -38
  229. sphinx/registry.py +35 -29
  230. sphinx/roles.py +9 -4
  231. sphinx/search/__init__.py +5 -17
  232. sphinx/search/da.py +1 -1
  233. sphinx/search/de.py +1 -1
  234. sphinx/search/en.py +1 -1
  235. sphinx/search/es.py +1 -1
  236. sphinx/search/fi.py +1 -1
  237. sphinx/search/fr.py +1 -1
  238. sphinx/search/hu.py +1 -1
  239. sphinx/search/it.py +1 -1
  240. sphinx/search/ja.py +1 -1
  241. sphinx/search/nl.py +1 -1
  242. sphinx/search/no.py +1 -1
  243. sphinx/search/pt.py +1 -1
  244. sphinx/search/ro.py +1 -1
  245. sphinx/search/ru.py +1 -1
  246. sphinx/search/sv.py +1 -1
  247. sphinx/search/tr.py +1 -1
  248. sphinx/search/zh.py +1 -1
  249. sphinx/testing/fixtures.py +23 -30
  250. sphinx/testing/path.py +9 -0
  251. sphinx/testing/restructuredtext.py +13 -5
  252. sphinx/testing/util.py +20 -63
  253. sphinx/texinputs/sphinxlatexobjects.sty +15 -15
  254. sphinx/themes/agogo/static/agogo.css_t +10 -4
  255. sphinx/themes/basic/layout.html +1 -1
  256. sphinx/themes/basic/static/basic.css_t +4 -0
  257. sphinx/themes/basic/static/documentation_options.js_t +1 -2
  258. sphinx/themes/basic/static/searchtools.js +17 -9
  259. sphinx/themes/basic/static/sphinx_highlight.js +13 -3
  260. sphinx/themes/bizstyle/static/bizstyle.css_t +4 -0
  261. sphinx/themes/classic/theme.conf +1 -1
  262. sphinx/themes/epub/static/epub.css_t +6 -1
  263. sphinx/themes/haiku/theme.conf +1 -1
  264. sphinx/themes/nature/static/nature.css_t +4 -0
  265. sphinx/themes/nonav/static/nonav.css_t +6 -1
  266. sphinx/themes/pyramid/static/pyramid.css_t +4 -0
  267. sphinx/themes/scrolls/static/scrolls.css_t +4 -0
  268. sphinx/themes/scrolls/theme.conf +1 -1
  269. sphinx/themes/sphinxdoc/static/sphinxdoc.css_t +4 -0
  270. sphinx/theming.py +9 -7
  271. sphinx/transforms/__init__.py +79 -3
  272. sphinx/transforms/compact_bullet_list.py +6 -3
  273. sphinx/transforms/i18n.py +26 -10
  274. sphinx/transforms/post_transforms/__init__.py +21 -8
  275. sphinx/transforms/post_transforms/code.py +6 -3
  276. sphinx/transforms/post_transforms/images.py +13 -9
  277. sphinx/util/__init__.py +21 -92
  278. sphinx/util/cfamily.py +7 -4
  279. sphinx/util/display.py +3 -2
  280. sphinx/util/docfields.py +7 -6
  281. sphinx/util/docstrings.py +1 -1
  282. sphinx/util/docutils.py +41 -31
  283. sphinx/util/fileutil.py +9 -6
  284. sphinx/util/i18n.py +21 -18
  285. sphinx/util/images.py +2 -1
  286. sphinx/util/index_entries.py +27 -0
  287. sphinx/util/inspect.py +83 -67
  288. sphinx/util/inventory.py +4 -2
  289. sphinx/util/logging.py +9 -6
  290. sphinx/util/matching.py +5 -2
  291. sphinx/util/math.py +6 -3
  292. sphinx/util/nodes.py +70 -31
  293. sphinx/util/osutil.py +22 -40
  294. sphinx/util/parallel.py +4 -1
  295. sphinx/util/rst.py +7 -3
  296. sphinx/util/tags.py +11 -4
  297. sphinx/util/template.py +17 -14
  298. sphinx/util/typing.py +61 -20
  299. sphinx/versioning.py +6 -4
  300. sphinx/writers/html.py +1 -1
  301. sphinx/writers/html5.py +32 -24
  302. sphinx/writers/latex.py +67 -53
  303. sphinx/writers/manpage.py +9 -5
  304. sphinx/writers/texinfo.py +11 -9
  305. sphinx/writers/text.py +14 -9
  306. sphinx/writers/xml.py +3 -2
  307. {sphinx-7.1.2.dist-info → sphinx-7.2.0.dist-info}/METADATA +7 -5
  308. sphinx-7.2.0.dist-info/RECORD +568 -0
  309. sphinx/testing/comparer.py +0 -97
  310. sphinx-7.1.2.dist-info/RECORD +0 -564
  311. {sphinx-7.1.2.dist-info → sphinx-7.2.0.dist-info}/LICENSE +0 -0
  312. {sphinx-7.1.2.dist-info → sphinx-7.2.0.dist-info}/WHEEL +0 -0
  313. {sphinx-7.1.2.dist-info → sphinx-7.2.0.dist-info}/entry_points.txt +0 -0
sphinx/domains/index.py CHANGED
@@ -2,22 +2,26 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import TYPE_CHECKING, Any, Iterable
5
+ from typing import TYPE_CHECKING, Any
6
6
 
7
7
  from docutils import nodes
8
- from docutils.nodes import Node, system_message
9
8
  from docutils.parsers.rst import directives
10
9
 
11
10
  from sphinx import addnodes
12
11
  from sphinx.domains import Domain
13
- from sphinx.environment import BuildEnvironment
14
- from sphinx.util import logging, split_index_msg
12
+ from sphinx.util import logging
15
13
  from sphinx.util.docutils import ReferenceRole, SphinxDirective
14
+ from sphinx.util.index_entries import split_index_msg
16
15
  from sphinx.util.nodes import process_index_entry
17
- from sphinx.util.typing import OptionSpec
18
16
 
19
17
  if TYPE_CHECKING:
18
+ from collections.abc import Iterable
19
+
20
+ from docutils.nodes import Node, system_message
21
+
20
22
  from sphinx.application import Sphinx
23
+ from sphinx.environment import BuildEnvironment
24
+ from sphinx.util.typing import OptionSpec
21
25
 
22
26
 
23
27
  logger = logging.getLogger(__name__)
@@ -2,32 +2,38 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import Any, Iterator, Tuple, cast
5
+ import contextlib
6
+ from typing import TYPE_CHECKING, Any, cast
6
7
 
7
8
  from docutils import nodes
8
- from docutils.nodes import Element, Node
9
9
  from docutils.parsers.rst import directives
10
10
 
11
11
  from sphinx import addnodes
12
- from sphinx.addnodes import desc_signature, pending_xref
13
- from sphinx.application import Sphinx
14
- from sphinx.builders import Builder
15
12
  from sphinx.directives import ObjectDescription
16
13
  from sphinx.domains import Domain, ObjType
17
14
  from sphinx.domains.python import _pseudo_parse_arglist
18
- from sphinx.environment import BuildEnvironment
19
15
  from sphinx.locale import _, __
20
16
  from sphinx.roles import XRefRole
21
17
  from sphinx.util import logging
22
18
  from sphinx.util.docfields import Field, GroupedField, TypedField
23
19
  from sphinx.util.docutils import SphinxDirective
24
20
  from sphinx.util.nodes import make_id, make_refnode, nested_parse_with_titles
25
- from sphinx.util.typing import OptionSpec
21
+
22
+ if TYPE_CHECKING:
23
+ from collections.abc import Iterator
24
+
25
+ from docutils.nodes import Element, Node
26
+
27
+ from sphinx.addnodes import desc_signature, pending_xref
28
+ from sphinx.application import Sphinx
29
+ from sphinx.builders import Builder
30
+ from sphinx.environment import BuildEnvironment
31
+ from sphinx.util.typing import OptionSpec
26
32
 
27
33
  logger = logging.getLogger(__name__)
28
34
 
29
35
 
30
- class JSObject(ObjectDescription[Tuple[str, str]]):
36
+ class JSObject(ObjectDescription[tuple[str, str]]):
31
37
  """
32
38
  Description of a JavaScript object.
33
39
  """
@@ -40,6 +46,10 @@ class JSObject(ObjectDescription[Tuple[str, str]]):
40
46
  allow_nesting = False
41
47
 
42
48
  option_spec: OptionSpec = {
49
+ 'no-index': directives.flag,
50
+ 'no-index-entry': directives.flag,
51
+ 'no-contents-entry': directives.flag,
52
+ 'no-typesetting': directives.flag,
43
53
  'noindex': directives.flag,
44
54
  'noindexentry': directives.flag,
45
55
  'nocontentsentry': directives.flag,
@@ -142,7 +152,7 @@ class JSObject(ObjectDescription[Tuple[str, str]]):
142
152
  domain = cast(JavaScriptDomain, self.env.get_domain('js'))
143
153
  domain.note_object(fullname, self.objtype, node_id, location=signode)
144
154
 
145
- if 'noindexentry' not in self.options:
155
+ if 'no-index-entry' not in self.options:
146
156
  indextext = self.get_index_text(mod_name, name_obj) # type: ignore[arg-type]
147
157
  if indextext:
148
158
  self.indexnode['entries'].append(('single', indextext, node_id, '', None))
@@ -209,10 +219,9 @@ class JSObject(ObjectDescription[Tuple[str, str]]):
209
219
  """
210
220
  objects = self.env.ref_context.setdefault('js:objects', [])
211
221
  if self.allow_nesting:
212
- try:
222
+ with contextlib.suppress(IndexError):
213
223
  objects.pop()
214
- except IndexError:
215
- pass
224
+
216
225
  self.env.ref_context['js:object'] = (objects[-1] if len(objects) > 0
217
226
  else None)
218
227
 
@@ -274,8 +283,8 @@ class JSModule(SphinxDirective):
274
283
  Options
275
284
  -------
276
285
 
277
- noindex
278
- If the ``noindex`` option is specified, no linkable elements will be
286
+ no-index
287
+ If the ``:no-index:`` option is specified, no linkable elements will be
279
288
  created, and the module won't be added to the global module index. This
280
289
  is useful for splitting up the module definition across multiple
281
290
  sections or files.
@@ -288,6 +297,9 @@ class JSModule(SphinxDirective):
288
297
  optional_arguments = 0
289
298
  final_argument_whitespace = False
290
299
  option_spec: OptionSpec = {
300
+ 'no-index': directives.flag,
301
+ 'no-contents-entry': directives.flag,
302
+ 'no-typesetting': directives.flag,
291
303
  'noindex': directives.flag,
292
304
  'nocontentsentry': directives.flag,
293
305
  }
@@ -295,7 +307,7 @@ class JSModule(SphinxDirective):
295
307
  def run(self) -> list[Node]:
296
308
  mod_name = self.arguments[0].strip()
297
309
  self.env.ref_context['js:module'] = mod_name
298
- noindex = 'noindex' in self.options
310
+ no_index = 'no-index' in self.options
299
311
 
300
312
  content_node: Element = nodes.section()
301
313
  # necessary so that the child nodes get the right source/line set
@@ -303,7 +315,7 @@ class JSModule(SphinxDirective):
303
315
  nested_parse_with_titles(self.state, self.content, content_node, self.content_offset)
304
316
 
305
317
  ret: list[Node] = []
306
- if not noindex:
318
+ if not no_index:
307
319
  domain = cast(JavaScriptDomain, self.env.get_domain('js'))
308
320
 
309
321
  node_id = make_id(self.env, self.state.document, 'module', mod_name)
@@ -313,12 +325,13 @@ class JSModule(SphinxDirective):
313
325
  domain.note_object(mod_name, 'module', node_id,
314
326
  location=(self.env.docname, self.lineno))
315
327
 
316
- target = nodes.target('', '', ids=[node_id], ismod=True)
317
- self.state.document.note_explicit_target(target)
318
- ret.append(target)
328
+ # The node order is: index node first, then target node
319
329
  indextext = _('%s (module)') % mod_name
320
330
  inode = addnodes.index(entries=[('single', indextext, node_id, '', None)])
321
331
  ret.append(inode)
332
+ target = nodes.target('', '', ids=[node_id], ismod=True)
333
+ self.state.document.note_explicit_target(target)
334
+ ret.append(target)
322
335
  ret.extend(content_node.children)
323
336
  return ret
324
337
 
sphinx/domains/math.py CHANGED
@@ -2,22 +2,24 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import TYPE_CHECKING, Any, Iterable
5
+ from typing import TYPE_CHECKING, Any
6
6
 
7
7
  from docutils import nodes
8
8
  from docutils.nodes import Element, Node, make_id, system_message
9
9
 
10
- from sphinx.addnodes import pending_xref
11
10
  from sphinx.domains import Domain
12
- from sphinx.environment import BuildEnvironment
13
11
  from sphinx.locale import __
14
12
  from sphinx.roles import XRefRole
15
13
  from sphinx.util import logging
16
14
  from sphinx.util.nodes import make_refnode
17
15
 
18
16
  if TYPE_CHECKING:
17
+ from collections.abc import Iterable
18
+
19
+ from sphinx.addnodes import pending_xref
19
20
  from sphinx.application import Sphinx
20
21
  from sphinx.builders import Builder
22
+ from sphinx.environment import BuildEnvironment
21
23
 
22
24
 
23
25
  logger = logging.getLogger(__name__)
sphinx/domains/python.py CHANGED
@@ -4,25 +4,21 @@ from __future__ import annotations
4
4
 
5
5
  import ast
6
6
  import builtins
7
+ import contextlib
7
8
  import inspect
8
9
  import re
9
10
  import token
10
11
  import typing
11
12
  from inspect import Parameter
12
- from typing import Any, Iterable, Iterator, List, NamedTuple, Tuple, cast
13
+ from typing import TYPE_CHECKING, Any, NamedTuple, cast
13
14
 
14
15
  from docutils import nodes
15
- from docutils.nodes import Element, Node
16
16
  from docutils.parsers.rst import directives
17
- from docutils.parsers.rst.states import Inliner
18
17
 
19
18
  from sphinx import addnodes
20
19
  from sphinx.addnodes import desc_signature, pending_xref, pending_xref_condition
21
- from sphinx.application import Sphinx
22
- from sphinx.builders import Builder
23
20
  from sphinx.directives import ObjectDescription
24
21
  from sphinx.domains import Domain, Index, IndexEntry, ObjType
25
- from sphinx.environment import BuildEnvironment
26
22
  from sphinx.locale import _, __
27
23
  from sphinx.pycode.parser import Token, TokenProcessor
28
24
  from sphinx.roles import XRefRole
@@ -36,7 +32,17 @@ from sphinx.util.nodes import (
36
32
  make_refnode,
37
33
  nested_parse_with_titles,
38
34
  )
39
- from sphinx.util.typing import OptionSpec, TextlikeNode
35
+
36
+ if TYPE_CHECKING:
37
+ from collections.abc import Iterable, Iterator
38
+
39
+ from docutils.nodes import Element, Node
40
+ from docutils.parsers.rst.states import Inliner
41
+
42
+ from sphinx.application import Sphinx
43
+ from sphinx.builders import Builder
44
+ from sphinx.environment import BuildEnvironment
45
+ from sphinx.util.typing import OptionSpec, TextlikeNode
40
46
 
41
47
  logger = logging.getLogger(__name__)
42
48
 
@@ -105,7 +111,7 @@ def parse_reftarget(reftarget: str, suppress_prefix: bool = False,
105
111
  return reftype, reftarget, title, refspecific
106
112
 
107
113
 
108
- def type_to_xref(target: str, env: BuildEnvironment | None = None,
114
+ def type_to_xref(target: str, env: BuildEnvironment, *,
109
115
  suppress_prefix: bool = False) -> addnodes.pending_xref:
110
116
  """Convert a type string to a cross reference node."""
111
117
  if env:
@@ -131,7 +137,7 @@ def type_to_xref(target: str, env: BuildEnvironment | None = None,
131
137
  refspecific=refspecific, **kwargs)
132
138
 
133
139
 
134
- def _parse_annotation(annotation: str, env: BuildEnvironment | None) -> list[Node]:
140
+ def _parse_annotation(annotation: str, env: BuildEnvironment) -> list[Node]:
135
141
  """Parse type annotation."""
136
142
  short_literals = env.config.python_display_short_literal_types
137
143
 
@@ -162,8 +168,6 @@ def _parse_annotation(annotation: str, env: BuildEnvironment | None) -> list[Nod
162
168
  return [nodes.Text(repr(node.value))]
163
169
  if isinstance(node, ast.Expr):
164
170
  return unparse(node.value)
165
- if isinstance(node, ast.Index):
166
- return unparse(node.value)
167
171
  if isinstance(node, ast.Invert):
168
172
  return [addnodes.desc_sig_punctuation('', '~')]
169
173
  if isinstance(node, ast.List):
@@ -220,9 +224,6 @@ def _parse_annotation(annotation: str, env: BuildEnvironment | None) -> list[Nod
220
224
 
221
225
  def _unparse_pep_604_annotation(node: ast.Subscript) -> list[Node]:
222
226
  subscript = node.slice
223
- if isinstance(subscript, ast.Index):
224
- # py38 only
225
- subscript = subscript.value # type: ignore[assignment]
226
227
 
227
228
  flattened: list[Node] = []
228
229
  if isinstance(subscript, ast.Tuple):
@@ -271,25 +272,25 @@ class _TypeParameterListParser(TokenProcessor):
271
272
 
272
273
  def fetch_type_param_spec(self) -> list[Token]:
273
274
  tokens = []
274
- while self.fetch_token():
275
- tokens.append(self.current)
275
+ while current := self.fetch_token():
276
+ tokens.append(current)
276
277
  for ldelim, rdelim in ('(', ')'), ('{', '}'), ('[', ']'):
277
- if self.current == [token.OP, ldelim]:
278
+ if current == [token.OP, ldelim]:
278
279
  tokens += self.fetch_until([token.OP, rdelim])
279
280
  break
280
281
  else:
281
- if self.current == token.INDENT:
282
+ if current == token.INDENT:
282
283
  tokens += self.fetch_until(token.DEDENT)
283
- elif self.current.match(
284
+ elif current.match(
284
285
  [token.OP, ':'], [token.OP, '='], [token.OP, ',']):
285
286
  tokens.pop()
286
287
  break
287
288
  return tokens
288
289
 
289
290
  def parse(self) -> None:
290
- while self.fetch_token():
291
- if self.current == token.NAME:
292
- tp_name = self.current.value.strip()
291
+ while current := self.fetch_token():
292
+ if current == token.NAME:
293
+ tp_name = current.value.strip()
293
294
  if self.previous and self.previous.match([token.OP, '*'], [token.OP, '**']):
294
295
  if self.previous == [token.OP, '*']:
295
296
  tp_kind = Parameter.VAR_POSITIONAL
@@ -301,19 +302,20 @@ class _TypeParameterListParser(TokenProcessor):
301
302
  tp_ann: Any = Parameter.empty
302
303
  tp_default: Any = Parameter.empty
303
304
 
304
- self.fetch_token()
305
- if self.current and self.current.match([token.OP, ':'], [token.OP, '=']):
306
- if self.current == [token.OP, ':']:
305
+ current = self.fetch_token()
306
+ if current and current.match([token.OP, ':'], [token.OP, '=']):
307
+ if current == [token.OP, ':']:
307
308
  tokens = self.fetch_type_param_spec()
308
309
  tp_ann = self._build_identifier(tokens)
309
310
 
310
- if self.current == [token.OP, '=']:
311
+ if self.current and self.current == [token.OP, '=']:
311
312
  tokens = self.fetch_type_param_spec()
312
313
  tp_default = self._build_identifier(tokens)
313
314
 
314
315
  if tp_kind != Parameter.POSITIONAL_OR_KEYWORD and tp_ann != Parameter.empty:
315
- raise SyntaxError('type parameter bound or constraint is not allowed '
316
- f'for {tp_kind.description} parameters')
316
+ msg = ('type parameter bound or constraint is not allowed '
317
+ f'for {tp_kind.description} parameters')
318
+ raise SyntaxError(msg)
317
319
 
318
320
  type_param = (tp_name, tp_kind, tp_default, tp_ann)
319
321
  self.type_params.append(type_param)
@@ -331,7 +333,7 @@ class _TypeParameterListParser(TokenProcessor):
331
333
  yield a, b, c
332
334
 
333
335
  idents: list[str] = []
334
- tokens: Iterable[Token] = iter(tokens) # type: ignore
336
+ tokens: Iterable[Token] = iter(tokens) # type: ignore[no-redef]
335
337
  # do not format opening brackets
336
338
  for tok in tokens:
337
339
  if not tok.match([token.OP, '('], [token.OP, '['], [token.OP, '{']):
@@ -397,7 +399,7 @@ class _TypeParameterListParser(TokenProcessor):
397
399
 
398
400
 
399
401
  def _parse_type_list(
400
- tp_list: str, env: BuildEnvironment | None = None,
402
+ tp_list: str, env: BuildEnvironment,
401
403
  multi_line_parameter_list: bool = False,
402
404
  ) -> addnodes.desc_type_parameter_list:
403
405
  """Parse a list of type parameters according to PEP 695."""
@@ -410,8 +412,9 @@ def _parse_type_list(
410
412
  for (tp_name, tp_kind, tp_default, tp_ann) in parser.type_params:
411
413
  # no positional-only or keyword-only allowed in a type parameters list
412
414
  if tp_kind in {Parameter.POSITIONAL_ONLY, Parameter.KEYWORD_ONLY}:
413
- raise SyntaxError('positional-only or keyword-only parameters'
414
- ' are prohibited in type parameter lists')
415
+ msg = ('positional-only or keyword-only parameters '
416
+ 'are prohibited in type parameter lists')
417
+ raise SyntaxError(msg)
415
418
 
416
419
  node = addnodes.desc_type_parameter()
417
420
  if tp_kind == Parameter.VAR_POSITIONAL:
@@ -458,7 +461,7 @@ def _parse_type_list(
458
461
 
459
462
 
460
463
  def _parse_arglist(
461
- arglist: str, env: BuildEnvironment | None = None, multi_line_parameter_list: bool = False,
464
+ arglist: str, env: BuildEnvironment, multi_line_parameter_list: bool = False,
462
465
  ) -> addnodes.desc_parameterlist:
463
466
  """Parse a list of arguments using AST parser"""
464
467
  params = addnodes.desc_parameterlist(arglist)
@@ -489,7 +492,7 @@ def _parse_arglist(
489
492
  children = _parse_annotation(param.annotation, env)
490
493
  node += addnodes.desc_sig_punctuation('', ':')
491
494
  node += addnodes.desc_sig_space()
492
- node += addnodes.desc_sig_name('', '', *children) # type: ignore
495
+ node += addnodes.desc_sig_name('', '', *children) # type: ignore[arg-type]
493
496
  if param.default is not param.empty:
494
497
  if param.annotation is not param.empty:
495
498
  node += addnodes.desc_sig_space()
@@ -578,10 +581,11 @@ class PyXrefMixin:
578
581
  ) -> Node:
579
582
  # we use inliner=None to make sure we get the old behaviour with a single
580
583
  # pending_xref node
581
- result = super().make_xref(rolename, domain, target, # type: ignore
584
+ result = super().make_xref(rolename, domain, target, # type: ignore[misc]
582
585
  innernode, contnode,
583
586
  env, inliner=None, location=None)
584
587
  if isinstance(result, pending_xref):
588
+ assert env is not None
585
589
  result['refspecific'] = True
586
590
  result['py:module'] = env.ref_context.get('py:module')
587
591
  result['py:class'] = env.ref_context.get('py:class')
@@ -652,7 +656,7 @@ class PyTypedField(PyXrefMixin, TypedField):
652
656
  pass
653
657
 
654
658
 
655
- class PyObject(ObjectDescription[Tuple[str, str]]):
659
+ class PyObject(ObjectDescription[tuple[str, str]]):
656
660
  """
657
661
  Description of a general Python object.
658
662
 
@@ -660,6 +664,10 @@ class PyObject(ObjectDescription[Tuple[str, str]]):
660
664
  :vartype allow_nesting: bool
661
665
  """
662
666
  option_spec: OptionSpec = {
667
+ 'no-index': directives.flag,
668
+ 'no-index-entry': directives.flag,
669
+ 'no-contents-entry': directives.flag,
670
+ 'no-typesetting': directives.flag,
663
671
  'noindex': directives.flag,
664
672
  'noindexentry': directives.flag,
665
673
  'nocontentsentry': directives.flag,
@@ -771,10 +779,10 @@ class PyObject(ObjectDescription[Tuple[str, str]]):
771
779
  sig_prefix = self.get_signature_prefix(sig)
772
780
  if sig_prefix:
773
781
  if type(sig_prefix) is str:
774
- raise TypeError(
775
- "Python directive method get_signature_prefix()"
776
- " must return a list of nodes."
777
- f" Return value was '{sig_prefix}'.")
782
+ msg = ("Python directive method get_signature_prefix()"
783
+ " must return a list of nodes."
784
+ f" Return value was '{sig_prefix}'.")
785
+ raise TypeError(msg)
778
786
  signode += addnodes.desc_annotation(str(sig_prefix), '', *sig_prefix)
779
787
 
780
788
  if prefix:
@@ -836,7 +844,8 @@ class PyObject(ObjectDescription[Tuple[str, str]]):
836
844
 
837
845
  def get_index_text(self, modname: str, name: tuple[str, str]) -> str:
838
846
  """Return the text for the index entry of the object."""
839
- raise NotImplementedError('must be implemented in subclasses')
847
+ msg = 'must be implemented in subclasses'
848
+ raise NotImplementedError(msg)
840
849
 
841
850
  def add_target_and_index(self, name_cls: tuple[str, str], sig: str,
842
851
  signode: desc_signature) -> None:
@@ -854,7 +863,7 @@ class PyObject(ObjectDescription[Tuple[str, str]]):
854
863
  domain.note_object(canonical_name, self.objtype, node_id, aliased=True,
855
864
  location=signode)
856
865
 
857
- if 'noindexentry' not in self.options:
866
+ if 'no-index-entry' not in self.options:
858
867
  indextext = self.get_index_text(modname, name_cls)
859
868
  if indextext:
860
869
  self.indexnode['entries'].append(('single', indextext, node_id, '', None))
@@ -904,10 +913,9 @@ class PyObject(ObjectDescription[Tuple[str, str]]):
904
913
  """
905
914
  classes = self.env.ref_context.setdefault('py:classes', [])
906
915
  if self.allow_nesting:
907
- try:
916
+ with contextlib.suppress(IndexError):
908
917
  classes.pop()
909
- except IndexError:
910
- pass
918
+
911
919
  self.env.ref_context['py:class'] = (classes[-1] if len(classes) > 0
912
920
  else None)
913
921
  if 'module' in self.options:
@@ -958,7 +966,7 @@ class PyFunction(PyObject):
958
966
  def add_target_and_index(self, name_cls: tuple[str, str], sig: str,
959
967
  signode: desc_signature) -> None:
960
968
  super().add_target_and_index(name_cls, sig, signode)
961
- if 'noindexentry' not in self.options:
969
+ if 'no-index-entry' not in self.options:
962
970
  modname = self.options.get('module', self.env.ref_context.get('py:module'))
963
971
  node_id = signode['ids'][0]
964
972
 
@@ -970,9 +978,9 @@ class PyFunction(PyObject):
970
978
  text = f'built-in function; {name}()'
971
979
  self.indexnode['entries'].append(('pair', text, node_id, '', None))
972
980
 
973
- def get_index_text(self, modname: str, name_cls: tuple[str, str]) -> str | None:
981
+ def get_index_text(self, modname: str, name_cls: tuple[str, str]) -> str:
974
982
  # add index in own add_target_and_index() instead.
975
- return None
983
+ return ''
976
984
 
977
985
 
978
986
  class PyDecoratorFunction(PyFunction):
@@ -1261,6 +1269,9 @@ class PyModule(SphinxDirective):
1261
1269
  option_spec: OptionSpec = {
1262
1270
  'platform': lambda x: x,
1263
1271
  'synopsis': lambda x: x,
1272
+ 'no-index': directives.flag,
1273
+ 'no-contents-entry': directives.flag,
1274
+ 'no-typesetting': directives.flag,
1264
1275
  'noindex': directives.flag,
1265
1276
  'nocontentsentry': directives.flag,
1266
1277
  'deprecated': directives.flag,
@@ -1270,7 +1281,7 @@ class PyModule(SphinxDirective):
1270
1281
  domain = cast(PythonDomain, self.env.get_domain('py'))
1271
1282
 
1272
1283
  modname = self.arguments[0].strip()
1273
- noindex = 'noindex' in self.options
1284
+ no_index = 'no-index' in self.options
1274
1285
  self.env.ref_context['py:module'] = modname
1275
1286
 
1276
1287
  content_node: Element = nodes.section()
@@ -1279,7 +1290,7 @@ class PyModule(SphinxDirective):
1279
1290
  nested_parse_with_titles(self.state, self.content, content_node, self.content_offset)
1280
1291
 
1281
1292
  ret: list[Node] = []
1282
- if not noindex:
1293
+ if not no_index:
1283
1294
  # note module to the domain
1284
1295
  node_id = make_id(self.env, self.state.document, 'module', modname)
1285
1296
  target = nodes.target('', '', ids=[node_id], ismod=True)
@@ -1295,10 +1306,11 @@ class PyModule(SphinxDirective):
1295
1306
 
1296
1307
  # the platform and synopsis aren't printed; in fact, they are only
1297
1308
  # used in the modindex currently
1298
- ret.append(target)
1299
1309
  indextext = f'module; {modname}'
1300
1310
  inode = addnodes.index(entries=[('pair', indextext, node_id, '', None)])
1311
+ # The node order is: index node first, then target node.
1301
1312
  ret.append(inode)
1313
+ ret.append(target)
1302
1314
  ret.extend(content_node.children)
1303
1315
  return ret
1304
1316
 
@@ -1354,7 +1366,7 @@ def filter_meta_fields(app: Sphinx, domain: str, objtype: str, content: Element)
1354
1366
 
1355
1367
  for node in content:
1356
1368
  if isinstance(node, nodes.field_list):
1357
- fields = cast(List[nodes.field], node)
1369
+ fields = cast(list[nodes.field], node)
1358
1370
  # removing list items while iterating the list needs reversed()
1359
1371
  for field in reversed(fields):
1360
1372
  field_name = cast(nodes.field_body, field[0]).astext().strip()
@@ -1506,7 +1518,7 @@ class PythonDomain(Domain):
1506
1518
  else:
1507
1519
  # duplicated
1508
1520
  logger.warning(__('duplicate object description of %s, '
1509
- 'other instance in %s, use :noindex: for one of them'),
1521
+ 'other instance in %s, use :no-index: for one of them'),
1510
1522
  name, other.docname, location=location)
1511
1523
  self.objects[name] = ObjectEntry(self.env.docname, node_id, objtype, aliased)
1512
1524
 
@@ -1558,7 +1570,7 @@ class PythonDomain(Domain):
1558
1570
  newname = None
1559
1571
  if searchmode == 1:
1560
1572
  if type is None:
1561
- objtypes = list(self.object_types)
1573
+ objtypes: list[str] | None = list(self.object_types)
1562
1574
  else:
1563
1575
  objtypes = self.objtypes_for_role(type)
1564
1576
  if objtypes is not None:
@@ -1673,9 +1685,9 @@ class PythonDomain(Domain):
1673
1685
  # if not found, use contnode
1674
1686
  children = [contnode]
1675
1687
 
1676
- results.append(('py:' + self.role_for_objtype(obj[2]),
1677
- make_refnode(builder, fromdocname, obj[0], obj[1],
1678
- children, name)))
1688
+ role = 'py:' + self.role_for_objtype(obj[2]) # type: ignore[operator]
1689
+ results.append((role, make_refnode(builder, fromdocname, obj[0], obj[1],
1690
+ children, name)))
1679
1691
  return results
1680
1692
 
1681
1693
  def _make_module_refnode(self, builder: Builder, fromdocname: str, name: str,
sphinx/domains/rst.py CHANGED
@@ -3,23 +3,28 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import re
6
- from typing import Any, Iterator, cast
6
+ from typing import TYPE_CHECKING, Any, cast
7
7
 
8
- from docutils.nodes import Element
9
8
  from docutils.parsers.rst import directives
10
9
 
11
10
  from sphinx import addnodes
12
- from sphinx.addnodes import desc_signature, pending_xref
13
- from sphinx.application import Sphinx
14
- from sphinx.builders import Builder
15
11
  from sphinx.directives import ObjectDescription
16
12
  from sphinx.domains import Domain, ObjType
17
- from sphinx.environment import BuildEnvironment
18
13
  from sphinx.locale import _, __
19
14
  from sphinx.roles import XRefRole
20
15
  from sphinx.util import logging
21
16
  from sphinx.util.nodes import make_id, make_refnode
22
- from sphinx.util.typing import OptionSpec
17
+
18
+ if TYPE_CHECKING:
19
+ from collections.abc import Iterator
20
+
21
+ from docutils.nodes import Element
22
+
23
+ from sphinx.addnodes import desc_signature, pending_xref
24
+ from sphinx.application import Sphinx
25
+ from sphinx.builders import Builder
26
+ from sphinx.environment import BuildEnvironment
27
+ from sphinx.util.typing import OptionSpec
23
28
 
24
29
  logger = logging.getLogger(__name__)
25
30
 
@@ -31,6 +36,10 @@ class ReSTMarkup(ObjectDescription[str]):
31
36
  Description of generic reST markup.
32
37
  """
33
38
  option_spec: OptionSpec = {
39
+ 'no-index': directives.flag,
40
+ 'no-index-entry': directives.flag,
41
+ 'no-contents-entry': directives.flag,
42
+ 'no-typesetting': directives.flag,
34
43
  'noindex': directives.flag,
35
44
  'noindexentry': directives.flag,
36
45
  'nocontentsentry': directives.flag,
@@ -44,7 +53,7 @@ class ReSTMarkup(ObjectDescription[str]):
44
53
  domain = cast(ReSTDomain, self.env.get_domain('rst'))
45
54
  domain.note_object(self.objtype, name, node_id, location=signode)
46
55
 
47
- if 'noindexentry' not in self.options:
56
+ if 'no-index-entry' not in self.options:
48
57
  indextext = self.get_index_text(self.objtype, name)
49
58
  if indextext:
50
59
  self.indexnode['entries'].append(('single', indextext, node_id, '', None))
@@ -137,7 +146,7 @@ class ReSTDirectiveOption(ReSTMarkup):
137
146
 
138
147
  def handle_signature(self, sig: str, signode: desc_signature) -> str:
139
148
  try:
140
- name, argument = re.split(r'\s*:\s+', sig.strip(), 1)
149
+ name, argument = re.split(r'\s*:\s+', sig.strip(), maxsplit=1)
141
150
  except ValueError:
142
151
  name, argument = sig, None
143
152
 
@@ -206,9 +215,9 @@ class ReSTDomain(Domain):
206
215
  label = 'reStructuredText'
207
216
 
208
217
  object_types = {
209
- 'directive': ObjType(_('directive'), 'dir'),
218
+ 'directive': ObjType(_('directive'), 'dir'),
210
219
  'directive:option': ObjType(_('directive-option'), 'dir'),
211
- 'role': ObjType(_('role'), 'role'),
220
+ 'role': ObjType(_('role'), 'role'),
212
221
  }
213
222
  directives = {
214
223
  'directive': ReSTDirective,