Sphinx 8.1.2__py3-none-any.whl → 8.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 (328) hide show
  1. sphinx/__init__.py +8 -4
  2. sphinx/__main__.py +2 -0
  3. sphinx/_cli/__init__.py +2 -5
  4. sphinx/_cli/util/colour.py +34 -11
  5. sphinx/_cli/util/errors.py +128 -61
  6. sphinx/addnodes.py +51 -35
  7. sphinx/application.py +362 -230
  8. sphinx/builders/__init__.py +87 -64
  9. sphinx/builders/_epub_base.py +65 -56
  10. sphinx/builders/changes.py +17 -23
  11. sphinx/builders/dirhtml.py +8 -13
  12. sphinx/builders/epub3.py +70 -38
  13. sphinx/builders/gettext.py +93 -73
  14. sphinx/builders/html/__init__.py +240 -186
  15. sphinx/builders/html/_assets.py +9 -2
  16. sphinx/builders/html/_build_info.py +3 -0
  17. sphinx/builders/latex/__init__.py +64 -54
  18. sphinx/builders/latex/constants.py +14 -11
  19. sphinx/builders/latex/nodes.py +2 -0
  20. sphinx/builders/latex/theming.py +8 -9
  21. sphinx/builders/latex/transforms.py +7 -5
  22. sphinx/builders/linkcheck.py +193 -149
  23. sphinx/builders/manpage.py +17 -17
  24. sphinx/builders/singlehtml.py +28 -16
  25. sphinx/builders/texinfo.py +28 -21
  26. sphinx/builders/text.py +10 -15
  27. sphinx/builders/xml.py +10 -19
  28. sphinx/cmd/build.py +49 -119
  29. sphinx/cmd/make_mode.py +35 -31
  30. sphinx/cmd/quickstart.py +78 -62
  31. sphinx/config.py +265 -163
  32. sphinx/directives/__init__.py +51 -54
  33. sphinx/directives/admonitions.py +107 -0
  34. sphinx/directives/code.py +24 -19
  35. sphinx/directives/other.py +21 -42
  36. sphinx/directives/patches.py +28 -16
  37. sphinx/domains/__init__.py +54 -31
  38. sphinx/domains/_domains_container.py +22 -17
  39. sphinx/domains/_index.py +5 -8
  40. sphinx/domains/c/__init__.py +366 -245
  41. sphinx/domains/c/_ast.py +378 -256
  42. sphinx/domains/c/_ids.py +89 -31
  43. sphinx/domains/c/_parser.py +283 -214
  44. sphinx/domains/c/_symbol.py +269 -198
  45. sphinx/domains/changeset.py +39 -24
  46. sphinx/domains/citation.py +54 -24
  47. sphinx/domains/cpp/__init__.py +517 -362
  48. sphinx/domains/cpp/_ast.py +999 -682
  49. sphinx/domains/cpp/_ids.py +133 -65
  50. sphinx/domains/cpp/_parser.py +746 -588
  51. sphinx/domains/cpp/_symbol.py +692 -489
  52. sphinx/domains/index.py +10 -8
  53. sphinx/domains/javascript.py +152 -74
  54. sphinx/domains/math.py +50 -40
  55. sphinx/domains/python/__init__.py +402 -211
  56. sphinx/domains/python/_annotations.py +134 -61
  57. sphinx/domains/python/_object.py +155 -68
  58. sphinx/domains/rst.py +94 -49
  59. sphinx/domains/std/__init__.py +510 -249
  60. sphinx/environment/__init__.py +345 -61
  61. sphinx/environment/adapters/asset.py +7 -1
  62. sphinx/environment/adapters/indexentries.py +15 -20
  63. sphinx/environment/adapters/toctree.py +19 -9
  64. sphinx/environment/collectors/__init__.py +3 -1
  65. sphinx/environment/collectors/asset.py +18 -15
  66. sphinx/environment/collectors/dependencies.py +8 -10
  67. sphinx/environment/collectors/metadata.py +6 -4
  68. sphinx/environment/collectors/title.py +3 -1
  69. sphinx/environment/collectors/toctree.py +4 -4
  70. sphinx/errors.py +1 -3
  71. sphinx/events.py +4 -4
  72. sphinx/ext/apidoc/__init__.py +66 -0
  73. sphinx/ext/apidoc/__main__.py +9 -0
  74. sphinx/ext/apidoc/_cli.py +356 -0
  75. sphinx/ext/apidoc/_extension.py +262 -0
  76. sphinx/ext/apidoc/_generate.py +356 -0
  77. sphinx/ext/apidoc/_shared.py +99 -0
  78. sphinx/ext/autodoc/__init__.py +837 -483
  79. sphinx/ext/autodoc/directive.py +57 -21
  80. sphinx/ext/autodoc/importer.py +184 -67
  81. sphinx/ext/autodoc/mock.py +25 -10
  82. sphinx/ext/autodoc/preserve_defaults.py +17 -9
  83. sphinx/ext/autodoc/type_comment.py +56 -29
  84. sphinx/ext/autodoc/typehints.py +49 -26
  85. sphinx/ext/autosectionlabel.py +28 -11
  86. sphinx/ext/autosummary/__init__.py +281 -142
  87. sphinx/ext/autosummary/generate.py +121 -51
  88. sphinx/ext/coverage.py +152 -91
  89. sphinx/ext/doctest.py +169 -101
  90. sphinx/ext/duration.py +12 -6
  91. sphinx/ext/extlinks.py +33 -21
  92. sphinx/ext/githubpages.py +8 -8
  93. sphinx/ext/graphviz.py +175 -109
  94. sphinx/ext/ifconfig.py +11 -6
  95. sphinx/ext/imgconverter.py +48 -25
  96. sphinx/ext/imgmath.py +127 -97
  97. sphinx/ext/inheritance_diagram.py +177 -103
  98. sphinx/ext/intersphinx/__init__.py +22 -13
  99. sphinx/ext/intersphinx/__main__.py +3 -1
  100. sphinx/ext/intersphinx/_cli.py +18 -14
  101. sphinx/ext/intersphinx/_load.py +91 -82
  102. sphinx/ext/intersphinx/_resolve.py +108 -74
  103. sphinx/ext/intersphinx/_shared.py +2 -2
  104. sphinx/ext/linkcode.py +28 -12
  105. sphinx/ext/mathjax.py +60 -29
  106. sphinx/ext/napoleon/__init__.py +19 -7
  107. sphinx/ext/napoleon/docstring.py +229 -231
  108. sphinx/ext/todo.py +44 -49
  109. sphinx/ext/viewcode.py +105 -57
  110. sphinx/extension.py +3 -1
  111. sphinx/highlighting.py +13 -7
  112. sphinx/io.py +9 -13
  113. sphinx/jinja2glue.py +29 -26
  114. sphinx/locale/__init__.py +8 -9
  115. sphinx/locale/ar/LC_MESSAGES/sphinx.mo +0 -0
  116. sphinx/locale/ar/LC_MESSAGES/sphinx.po +2155 -2050
  117. sphinx/locale/bg/LC_MESSAGES/sphinx.mo +0 -0
  118. sphinx/locale/bg/LC_MESSAGES/sphinx.po +2045 -1940
  119. sphinx/locale/bn/LC_MESSAGES/sphinx.mo +0 -0
  120. sphinx/locale/bn/LC_MESSAGES/sphinx.po +2175 -2070
  121. sphinx/locale/ca/LC_MESSAGES/sphinx.js +3 -3
  122. sphinx/locale/ca/LC_MESSAGES/sphinx.mo +0 -0
  123. sphinx/locale/ca/LC_MESSAGES/sphinx.po +2690 -2585
  124. sphinx/locale/ca@valencia/LC_MESSAGES/sphinx.js +63 -0
  125. sphinx/locale/ca@valencia/LC_MESSAGES/sphinx.mo +0 -0
  126. sphinx/locale/ca@valencia/LC_MESSAGES/sphinx.po +4216 -0
  127. sphinx/locale/cak/LC_MESSAGES/sphinx.mo +0 -0
  128. sphinx/locale/cak/LC_MESSAGES/sphinx.po +2096 -1991
  129. sphinx/locale/cs/LC_MESSAGES/sphinx.mo +0 -0
  130. sphinx/locale/cs/LC_MESSAGES/sphinx.po +2248 -2143
  131. sphinx/locale/cy/LC_MESSAGES/sphinx.mo +0 -0
  132. sphinx/locale/cy/LC_MESSAGES/sphinx.po +2201 -2096
  133. sphinx/locale/da/LC_MESSAGES/sphinx.mo +0 -0
  134. sphinx/locale/da/LC_MESSAGES/sphinx.po +2282 -2177
  135. sphinx/locale/de/LC_MESSAGES/sphinx.mo +0 -0
  136. sphinx/locale/de/LC_MESSAGES/sphinx.po +2261 -2156
  137. sphinx/locale/de_DE/LC_MESSAGES/sphinx.mo +0 -0
  138. sphinx/locale/de_DE/LC_MESSAGES/sphinx.po +2045 -1940
  139. sphinx/locale/el/LC_MESSAGES/sphinx.mo +0 -0
  140. sphinx/locale/el/LC_MESSAGES/sphinx.po +2604 -2499
  141. sphinx/locale/en_DE/LC_MESSAGES/sphinx.mo +0 -0
  142. sphinx/locale/en_DE/LC_MESSAGES/sphinx.po +2045 -1940
  143. sphinx/locale/en_FR/LC_MESSAGES/sphinx.mo +0 -0
  144. sphinx/locale/en_FR/LC_MESSAGES/sphinx.po +2045 -1940
  145. sphinx/locale/en_GB/LC_MESSAGES/sphinx.mo +0 -0
  146. sphinx/locale/en_GB/LC_MESSAGES/sphinx.po +2631 -2526
  147. sphinx/locale/en_HK/LC_MESSAGES/sphinx.mo +0 -0
  148. sphinx/locale/en_HK/LC_MESSAGES/sphinx.po +2045 -1940
  149. sphinx/locale/eo/LC_MESSAGES/sphinx.mo +0 -0
  150. sphinx/locale/eo/LC_MESSAGES/sphinx.po +2078 -1973
  151. sphinx/locale/es/LC_MESSAGES/sphinx.mo +0 -0
  152. sphinx/locale/es/LC_MESSAGES/sphinx.po +2633 -2528
  153. sphinx/locale/es_CO/LC_MESSAGES/sphinx.mo +0 -0
  154. sphinx/locale/es_CO/LC_MESSAGES/sphinx.po +2045 -1940
  155. sphinx/locale/et/LC_MESSAGES/sphinx.mo +0 -0
  156. sphinx/locale/et/LC_MESSAGES/sphinx.po +2449 -2344
  157. sphinx/locale/eu/LC_MESSAGES/sphinx.mo +0 -0
  158. sphinx/locale/eu/LC_MESSAGES/sphinx.po +2241 -2136
  159. sphinx/locale/fa/LC_MESSAGES/sphinx.mo +0 -0
  160. sphinx/locale/fa/LC_MESSAGES/sphinx.po +504 -500
  161. sphinx/locale/fi/LC_MESSAGES/sphinx.mo +0 -0
  162. sphinx/locale/fi/LC_MESSAGES/sphinx.po +499 -495
  163. sphinx/locale/fr/LC_MESSAGES/sphinx.mo +0 -0
  164. sphinx/locale/fr/LC_MESSAGES/sphinx.po +513 -509
  165. sphinx/locale/fr_FR/LC_MESSAGES/sphinx.mo +0 -0
  166. sphinx/locale/fr_FR/LC_MESSAGES/sphinx.po +499 -495
  167. sphinx/locale/gl/LC_MESSAGES/sphinx.mo +0 -0
  168. sphinx/locale/gl/LC_MESSAGES/sphinx.po +2644 -2539
  169. sphinx/locale/he/LC_MESSAGES/sphinx.mo +0 -0
  170. sphinx/locale/he/LC_MESSAGES/sphinx.po +499 -495
  171. sphinx/locale/hi/LC_MESSAGES/sphinx.mo +0 -0
  172. sphinx/locale/hi/LC_MESSAGES/sphinx.po +504 -500
  173. sphinx/locale/hi_IN/LC_MESSAGES/sphinx.mo +0 -0
  174. sphinx/locale/hi_IN/LC_MESSAGES/sphinx.po +499 -495
  175. sphinx/locale/hr/LC_MESSAGES/sphinx.mo +0 -0
  176. sphinx/locale/hr/LC_MESSAGES/sphinx.po +501 -497
  177. sphinx/locale/hu/LC_MESSAGES/sphinx.mo +0 -0
  178. sphinx/locale/hu/LC_MESSAGES/sphinx.po +499 -495
  179. sphinx/locale/id/LC_MESSAGES/sphinx.mo +0 -0
  180. sphinx/locale/id/LC_MESSAGES/sphinx.po +2609 -2504
  181. sphinx/locale/is/LC_MESSAGES/sphinx.mo +0 -0
  182. sphinx/locale/is/LC_MESSAGES/sphinx.po +499 -495
  183. sphinx/locale/it/LC_MESSAGES/sphinx.mo +0 -0
  184. sphinx/locale/it/LC_MESSAGES/sphinx.po +2265 -2160
  185. sphinx/locale/ja/LC_MESSAGES/sphinx.mo +0 -0
  186. sphinx/locale/ja/LC_MESSAGES/sphinx.po +2621 -2516
  187. sphinx/locale/ka/LC_MESSAGES/sphinx.mo +0 -0
  188. sphinx/locale/ka/LC_MESSAGES/sphinx.po +2567 -2462
  189. sphinx/locale/ko/LC_MESSAGES/sphinx.mo +0 -0
  190. sphinx/locale/ko/LC_MESSAGES/sphinx.po +2631 -2526
  191. sphinx/locale/lt/LC_MESSAGES/sphinx.mo +0 -0
  192. sphinx/locale/lt/LC_MESSAGES/sphinx.po +2214 -2109
  193. sphinx/locale/lv/LC_MESSAGES/sphinx.mo +0 -0
  194. sphinx/locale/lv/LC_MESSAGES/sphinx.po +2218 -2113
  195. sphinx/locale/mk/LC_MESSAGES/sphinx.mo +0 -0
  196. sphinx/locale/mk/LC_MESSAGES/sphinx.po +2088 -1983
  197. sphinx/locale/nb_NO/LC_MESSAGES/sphinx.mo +0 -0
  198. sphinx/locale/nb_NO/LC_MESSAGES/sphinx.po +2247 -2142
  199. sphinx/locale/ne/LC_MESSAGES/sphinx.mo +0 -0
  200. sphinx/locale/ne/LC_MESSAGES/sphinx.po +2227 -2122
  201. sphinx/locale/nl/LC_MESSAGES/sphinx.mo +0 -0
  202. sphinx/locale/nl/LC_MESSAGES/sphinx.po +2316 -2211
  203. sphinx/locale/pl/LC_MESSAGES/sphinx.js +2 -2
  204. sphinx/locale/pl/LC_MESSAGES/sphinx.mo +0 -0
  205. sphinx/locale/pl/LC_MESSAGES/sphinx.po +2442 -2336
  206. sphinx/locale/pt/LC_MESSAGES/sphinx.mo +0 -0
  207. sphinx/locale/pt/LC_MESSAGES/sphinx.po +2045 -1940
  208. sphinx/locale/pt_BR/LC_MESSAGES/sphinx.mo +0 -0
  209. sphinx/locale/pt_BR/LC_MESSAGES/sphinx.po +2657 -2552
  210. sphinx/locale/pt_PT/LC_MESSAGES/sphinx.mo +0 -0
  211. sphinx/locale/pt_PT/LC_MESSAGES/sphinx.po +2243 -2138
  212. sphinx/locale/ro/LC_MESSAGES/sphinx.mo +0 -0
  213. sphinx/locale/ro/LC_MESSAGES/sphinx.po +2244 -2139
  214. sphinx/locale/ru/LC_MESSAGES/sphinx.js +1 -1
  215. sphinx/locale/ru/LC_MESSAGES/sphinx.mo +0 -0
  216. sphinx/locale/ru/LC_MESSAGES/sphinx.po +2660 -2555
  217. sphinx/locale/si/LC_MESSAGES/sphinx.mo +0 -0
  218. sphinx/locale/si/LC_MESSAGES/sphinx.po +2134 -2029
  219. sphinx/locale/sk/LC_MESSAGES/sphinx.mo +0 -0
  220. sphinx/locale/sk/LC_MESSAGES/sphinx.po +2614 -2509
  221. sphinx/locale/sl/LC_MESSAGES/sphinx.mo +0 -0
  222. sphinx/locale/sl/LC_MESSAGES/sphinx.po +2167 -2062
  223. sphinx/locale/sphinx.pot +2069 -1964
  224. sphinx/locale/sq/LC_MESSAGES/sphinx.mo +0 -0
  225. sphinx/locale/sq/LC_MESSAGES/sphinx.po +2661 -2556
  226. sphinx/locale/sr/LC_MESSAGES/sphinx.mo +0 -0
  227. sphinx/locale/sr/LC_MESSAGES/sphinx.po +2213 -2108
  228. sphinx/locale/sv/LC_MESSAGES/sphinx.mo +0 -0
  229. sphinx/locale/sv/LC_MESSAGES/sphinx.po +2229 -2124
  230. sphinx/locale/te/LC_MESSAGES/sphinx.mo +0 -0
  231. sphinx/locale/te/LC_MESSAGES/sphinx.po +2045 -1940
  232. sphinx/locale/tr/LC_MESSAGES/sphinx.mo +0 -0
  233. sphinx/locale/tr/LC_MESSAGES/sphinx.po +2608 -2503
  234. sphinx/locale/uk_UA/LC_MESSAGES/sphinx.mo +0 -0
  235. sphinx/locale/uk_UA/LC_MESSAGES/sphinx.po +2167 -2062
  236. sphinx/locale/ur/LC_MESSAGES/sphinx.mo +0 -0
  237. sphinx/locale/ur/LC_MESSAGES/sphinx.po +2045 -1940
  238. sphinx/locale/vi/LC_MESSAGES/sphinx.mo +0 -0
  239. sphinx/locale/vi/LC_MESSAGES/sphinx.po +2204 -2099
  240. sphinx/locale/yue/LC_MESSAGES/sphinx.mo +0 -0
  241. sphinx/locale/yue/LC_MESSAGES/sphinx.po +2045 -1940
  242. sphinx/locale/zh_HK/LC_MESSAGES/sphinx.mo +0 -0
  243. sphinx/locale/zh_HK/LC_MESSAGES/sphinx.po +2045 -1940
  244. sphinx/locale/zh_TW/LC_MESSAGES/sphinx.mo +0 -0
  245. sphinx/locale/zh_TW/LC_MESSAGES/sphinx.po +2659 -2554
  246. sphinx/locale/zh_TW.Big5/LC_MESSAGES/sphinx.mo +0 -0
  247. sphinx/locale/zh_TW.Big5/LC_MESSAGES/sphinx.po +2045 -1940
  248. sphinx/parsers.py +8 -7
  249. sphinx/project.py +2 -2
  250. sphinx/pycode/__init__.py +31 -21
  251. sphinx/pycode/ast.py +6 -3
  252. sphinx/pycode/parser.py +14 -8
  253. sphinx/pygments_styles.py +4 -5
  254. sphinx/registry.py +192 -92
  255. sphinx/roles.py +58 -7
  256. sphinx/search/__init__.py +75 -54
  257. sphinx/search/en.py +11 -13
  258. sphinx/search/fi.py +1 -1
  259. sphinx/search/ja.py +8 -6
  260. sphinx/search/nl.py +1 -1
  261. sphinx/search/zh.py +19 -21
  262. sphinx/testing/fixtures.py +26 -29
  263. sphinx/testing/path.py +26 -62
  264. sphinx/testing/restructuredtext.py +14 -8
  265. sphinx/testing/util.py +21 -19
  266. sphinx/texinputs/make.bat.jinja +50 -50
  267. sphinx/texinputs/sphinx.sty +4 -3
  268. sphinx/texinputs/sphinxlatexadmonitions.sty +1 -1
  269. sphinx/texinputs/sphinxlatexobjects.sty +29 -10
  270. sphinx/themes/basic/static/searchtools.js +8 -5
  271. sphinx/theming.py +49 -61
  272. sphinx/transforms/__init__.py +17 -38
  273. sphinx/transforms/compact_bullet_list.py +5 -3
  274. sphinx/transforms/i18n.py +8 -21
  275. sphinx/transforms/post_transforms/__init__.py +142 -93
  276. sphinx/transforms/post_transforms/code.py +5 -5
  277. sphinx/transforms/post_transforms/images.py +28 -24
  278. sphinx/transforms/references.py +3 -1
  279. sphinx/util/__init__.py +109 -60
  280. sphinx/util/_files.py +39 -23
  281. sphinx/util/_importer.py +4 -1
  282. sphinx/util/_inventory_file_reader.py +76 -0
  283. sphinx/util/_io.py +2 -2
  284. sphinx/util/_lines.py +6 -3
  285. sphinx/util/_pathlib.py +40 -2
  286. sphinx/util/build_phase.py +2 -0
  287. sphinx/util/cfamily.py +19 -14
  288. sphinx/util/console.py +44 -179
  289. sphinx/util/display.py +9 -10
  290. sphinx/util/docfields.py +140 -122
  291. sphinx/util/docstrings.py +1 -1
  292. sphinx/util/docutils.py +118 -77
  293. sphinx/util/fileutil.py +25 -26
  294. sphinx/util/http_date.py +2 -0
  295. sphinx/util/i18n.py +77 -64
  296. sphinx/util/images.py +8 -6
  297. sphinx/util/inspect.py +147 -38
  298. sphinx/util/inventory.py +215 -116
  299. sphinx/util/logging.py +33 -33
  300. sphinx/util/matching.py +12 -4
  301. sphinx/util/nodes.py +18 -13
  302. sphinx/util/osutil.py +38 -39
  303. sphinx/util/parallel.py +22 -13
  304. sphinx/util/parsing.py +2 -1
  305. sphinx/util/png.py +6 -2
  306. sphinx/util/requests.py +33 -2
  307. sphinx/util/rst.py +3 -2
  308. sphinx/util/tags.py +1 -1
  309. sphinx/util/template.py +18 -10
  310. sphinx/util/texescape.py +8 -6
  311. sphinx/util/typing.py +148 -122
  312. sphinx/versioning.py +3 -3
  313. sphinx/writers/html.py +3 -1
  314. sphinx/writers/html5.py +63 -52
  315. sphinx/writers/latex.py +83 -67
  316. sphinx/writers/manpage.py +19 -38
  317. sphinx/writers/texinfo.py +47 -47
  318. sphinx/writers/text.py +50 -32
  319. sphinx/writers/xml.py +11 -8
  320. {sphinx-8.1.2.dist-info → sphinx-8.2.0.dist-info}/LICENSE.rst +1 -1
  321. {sphinx-8.1.2.dist-info → sphinx-8.2.0.dist-info}/METADATA +25 -15
  322. sphinx-8.2.0.dist-info/RECORD +606 -0
  323. {sphinx-8.1.2.dist-info → sphinx-8.2.0.dist-info}/WHEEL +1 -1
  324. sphinx/builders/html/transforms.py +0 -90
  325. sphinx/ext/apidoc.py +0 -721
  326. sphinx/util/exceptions.py +0 -74
  327. sphinx-8.1.2.dist-info/RECORD +0 -598
  328. {sphinx-8.1.2.dist-info → sphinx-8.2.0.dist-info}/entry_points.txt +0 -0
@@ -1,24 +1,27 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import TYPE_CHECKING, Any, NoReturn
3
+ from typing import TYPE_CHECKING
4
4
 
5
5
  from sphinx.domains.cpp._ast import (
6
6
  ASTDeclaration,
7
- ASTIdentifier,
8
7
  ASTNestedName,
9
8
  ASTNestedNameElement,
10
- ASTOperator,
11
- ASTTemplateArgs,
12
- ASTTemplateDeclarationPrefix,
13
- ASTTemplateIntroduction,
14
- ASTTemplateParams,
15
9
  )
16
10
  from sphinx.locale import __
17
11
  from sphinx.util import logging
18
12
 
19
13
  if TYPE_CHECKING:
20
- from collections.abc import Callable, Iterator
21
-
14
+ from collections.abc import Callable, Iterable, Iterator, Sequence
15
+ from typing import Any, NoReturn
16
+
17
+ from sphinx.domains.cpp._ast import (
18
+ ASTIdentifier,
19
+ ASTOperator,
20
+ ASTTemplateArgs,
21
+ ASTTemplateDeclarationPrefix,
22
+ ASTTemplateIntroduction,
23
+ ASTTemplateParams,
24
+ )
22
25
  from sphinx.environment import BuildEnvironment
23
26
 
24
27
  logger = logging.getLogger(__name__)
@@ -32,55 +35,117 @@ class _DuplicateSymbolError(Exception):
32
35
  self.declaration = declaration
33
36
 
34
37
  def __str__(self) -> str:
35
- return "Internal C++ duplicate symbol error:\n%s" % self.symbol.dump(0)
38
+ return 'Internal C++ duplicate symbol error:\n%s' % self.symbol.dump(0)
36
39
 
37
40
 
38
41
  class SymbolLookupResult:
39
- def __init__(self, symbols: Iterator[Symbol], parentSymbol: Symbol,
40
- identOrOp: ASTIdentifier | ASTOperator, templateParams: Any,
41
- templateArgs: ASTTemplateArgs) -> None:
42
+ __slots__ = (
43
+ 'symbols',
44
+ 'parent_symbol',
45
+ 'ident_or_op',
46
+ 'template_params',
47
+ 'template_args',
48
+ )
49
+
50
+ symbols: Iterable[Symbol]
51
+ parent_symbol: Symbol
52
+ ident_or_op: ASTIdentifier | ASTOperator
53
+ template_params: Any
54
+ template_args: ASTTemplateArgs
55
+
56
+ def __init__(
57
+ self,
58
+ symbols: Iterable[Symbol],
59
+ parent_symbol: Symbol,
60
+ ident_or_op: ASTIdentifier | ASTOperator,
61
+ template_params: Any,
62
+ template_args: ASTTemplateArgs,
63
+ ) -> None:
42
64
  self.symbols = symbols
43
- self.parentSymbol = parentSymbol
44
- self.identOrOp = identOrOp
45
- self.templateParams = templateParams
46
- self.templateArgs = templateArgs
65
+ self.parent_symbol = parent_symbol
66
+ self.ident_or_op = ident_or_op
67
+ self.template_params = template_params
68
+ self.template_args = template_args
69
+
70
+ @property
71
+ def parentSymbol(self) -> Symbol:
72
+ return self.parent_symbol
73
+
74
+ @property
75
+ def identOrOp(self) -> ASTIdentifier | ASTOperator:
76
+ return self.ident_or_op
77
+
78
+ @property
79
+ def templateParams(self) -> Any:
80
+ return self.template_params
81
+
82
+ @property
83
+ def templateArgs(self) -> ASTTemplateArgs:
84
+ return self.template_args
47
85
 
48
86
 
49
87
  class LookupKey:
50
- def __init__(self, data: list[tuple[ASTNestedNameElement,
51
- ASTTemplateParams | ASTTemplateIntroduction,
52
- str]]) -> None:
88
+ __slots__ = ('data',)
89
+
90
+ data: Sequence[
91
+ tuple[
92
+ ASTNestedNameElement,
93
+ ASTTemplateParams | ASTTemplateIntroduction,
94
+ str | None,
95
+ ]
96
+ ]
97
+
98
+ def __init__(
99
+ self,
100
+ data: Sequence[
101
+ tuple[
102
+ ASTNestedNameElement,
103
+ ASTTemplateParams | ASTTemplateIntroduction,
104
+ str | None,
105
+ ]
106
+ ],
107
+ /,
108
+ ) -> None:
53
109
  self.data = data
54
110
 
111
+ def __repr__(self) -> str:
112
+ return f'LookupKey({self.data!r})'
113
+
114
+ def __str__(self) -> str:
115
+ inner = ', '.join(f'({ident}, {id_})' for ident, _, id_ in self.data)
116
+ return f'[{inner}]'
55
117
 
56
- def _is_specialization(templateParams: ASTTemplateParams | ASTTemplateIntroduction,
57
- templateArgs: ASTTemplateArgs) -> bool:
58
- # Checks if `templateArgs` does not exactly match `templateParams`.
118
+
119
+ def _is_specialization(
120
+ template_params: ASTTemplateParams | ASTTemplateIntroduction,
121
+ template_args: ASTTemplateArgs,
122
+ ) -> bool:
123
+ # Checks if `template_args` does not exactly match `template_params`.
59
124
  # the names of the template parameters must be given exactly as args
60
125
  # and params that are packs must in the args be the name expanded
61
- if len(templateParams.params) != len(templateArgs.args):
126
+ if len(template_params.params) != len(template_args.args):
62
127
  return True
63
128
  # having no template params and no arguments is also a specialization
64
- if len(templateParams.params) == 0:
129
+ if len(template_params.params) == 0:
65
130
  return True
66
- for i in range(len(templateParams.params)):
67
- param = templateParams.params[i]
68
- arg = templateArgs.args[i]
131
+ for i in range(len(template_params.params)):
132
+ param = template_params.params[i]
133
+ arg = template_args.args[i]
69
134
  # TODO: doing this by string manipulation is probably not the most efficient
70
- paramName = str(param.name)
71
- argTxt = str(arg)
72
- isArgPackExpansion = argTxt.endswith('...')
73
- if param.isPack != isArgPackExpansion:
135
+ param_name = str(param.name)
136
+ arg_txt = str(arg)
137
+ is_arg_pack_expansion = arg_txt.endswith('...')
138
+ if param.isPack != is_arg_pack_expansion:
74
139
  return True
75
- argName = argTxt[:-3] if isArgPackExpansion else argTxt
76
- if paramName != argName:
140
+ arg_name = arg_txt[:-3] if is_arg_pack_expansion else arg_txt
141
+ if param_name != arg_name:
77
142
  return True
78
143
  return False
79
144
 
80
145
 
81
146
  class Symbol:
82
147
  debug_indent = 0
83
- debug_indent_string = " "
148
+ debug_indent_string = ' '
84
149
  debug_lookup = False # overridden by the corresponding config value
85
150
  debug_show_tree = False # overridden by the corresponding config value
86
151
 
@@ -95,7 +160,7 @@ class Symbol:
95
160
 
96
161
  @staticmethod
97
162
  def debug_print(*args: Any) -> None:
98
- logger.debug(Symbol.debug_indent_string * Symbol.debug_indent, end="")
163
+ logger.debug(Symbol.debug_indent_string * Symbol.debug_indent, end='')
99
164
  logger.debug(*args)
100
165
 
101
166
  def _assert_invariants(self) -> None:
@@ -111,15 +176,20 @@ class Symbol:
111
176
  assert self.docname
112
177
 
113
178
  def __setattr__(self, key: str, value: Any) -> None:
114
- if key == "children":
179
+ if key == 'children':
115
180
  raise AssertionError
116
181
  return super().__setattr__(key, value)
117
182
 
118
- def __init__(self, parent: Symbol | None,
119
- identOrOp: ASTIdentifier | ASTOperator | None,
120
- templateParams: ASTTemplateParams | ASTTemplateIntroduction | None,
121
- templateArgs: Any, declaration: ASTDeclaration | None,
122
- docname: str | None, line: int | None) -> None:
183
+ def __init__(
184
+ self,
185
+ parent: Symbol | None,
186
+ identOrOp: ASTIdentifier | ASTOperator | None,
187
+ templateParams: ASTTemplateParams | ASTTemplateIntroduction | None,
188
+ templateArgs: Any,
189
+ declaration: ASTDeclaration | None,
190
+ docname: str | None,
191
+ line: int | None,
192
+ ) -> None:
123
193
  self.parent = parent
124
194
  # declarations in a single directive are linked together
125
195
  self.siblingAbove: Symbol | None = None
@@ -132,8 +202,9 @@ class Symbol:
132
202
  # and
133
203
  #
134
204
  # .. cpp:function:: template <typename T> int A<T>::foo()
135
- if (templateArgs is not None and
136
- not _is_specialization(templateParams, templateArgs)):
205
+ if templateArgs is not None and not _is_specialization(
206
+ templateParams, templateArgs
207
+ ):
137
208
  templateArgs = None
138
209
  self.templateParams = templateParams # template<templateParams>
139
210
  self.templateArgs = templateArgs # identifier<templateArgs>
@@ -145,8 +216,8 @@ class Symbol:
145
216
 
146
217
  # Remember to modify Symbol.remove if modifications to the parent change.
147
218
  self._children: list[Symbol] = []
148
- self._anonChildren: list[Symbol] = []
149
- # note: _children includes _anonChildren
219
+ self._anon_children: list[Symbol] = []
220
+ # note: _children includes _anon_children
150
221
  if self.parent:
151
222
  self.parent._children.append(self)
152
223
  if self.declaration:
@@ -177,7 +248,7 @@ class Symbol:
177
248
  def _add_template_and_function_params(self) -> None:
178
249
  if Symbol.debug_lookup:
179
250
  Symbol.debug_indent += 1
180
- Symbol.debug_print("_add_template_and_function_params:")
251
+ Symbol.debug_print('_add_template_and_function_params:')
181
252
  # Note: we may be called from _fill_empty, so the symbols we want
182
253
  # to add may actually already be present (as empty symbols).
183
254
 
@@ -195,7 +266,10 @@ class Symbol:
195
266
  nn = ASTNestedName([nne], [False], rooted=False)
196
267
  self._add_symbols(nn, [], decl, self.docname, self.line)
197
268
  # add symbols for function parameters, if any
198
- if self.declaration is not None and self.declaration.function_params is not None:
269
+ if (
270
+ self.declaration is not None
271
+ and self.declaration.function_params is not None
272
+ ):
199
273
  for fp in self.declaration.function_params:
200
274
  if fp.arg is None:
201
275
  continue
@@ -218,26 +292,26 @@ class Symbol:
218
292
  self.parent = None
219
293
 
220
294
  def clear_doc(self, docname: str) -> None:
221
- newChildren: list[Symbol] = []
222
- for sChild in self._children:
223
- sChild.clear_doc(docname)
224
- if sChild.declaration and sChild.docname == docname:
225
- sChild.declaration = None
226
- sChild.docname = None
227
- sChild.line = None
228
- if sChild.siblingAbove is not None:
229
- sChild.siblingAbove.siblingBelow = sChild.siblingBelow
230
- if sChild.siblingBelow is not None:
231
- sChild.siblingBelow.siblingAbove = sChild.siblingAbove
232
- sChild.siblingAbove = None
233
- sChild.siblingBelow = None
234
- newChildren.append(sChild)
235
- self._children = newChildren
295
+ new_children: list[Symbol] = []
296
+ for s_child in self._children:
297
+ s_child.clear_doc(docname)
298
+ if s_child.declaration and s_child.docname == docname:
299
+ s_child.declaration = None
300
+ s_child.docname = None
301
+ s_child.line = None
302
+ if s_child.siblingAbove is not None:
303
+ s_child.siblingAbove.siblingBelow = s_child.siblingBelow
304
+ if s_child.siblingBelow is not None:
305
+ s_child.siblingBelow.siblingAbove = s_child.siblingAbove
306
+ s_child.siblingAbove = None
307
+ s_child.siblingBelow = None
308
+ new_children.append(s_child)
309
+ self._children = new_children
236
310
 
237
311
  def get_all_symbols(self) -> Iterator[Any]:
238
312
  yield self
239
- for sChild in self._children:
240
- yield from sChild.get_all_symbols()
313
+ for s_child in self._children:
314
+ yield from s_child.get_all_symbols()
241
315
 
242
316
  @property
243
317
  def children_recurse_anon(self) -> Iterator[Symbol]:
@@ -258,14 +332,14 @@ class Symbol:
258
332
  while s.parent:
259
333
  symbols.append(s)
260
334
  s = s.parent
261
- symbols.reverse()
262
- key = []
263
- for s in symbols:
264
- nne = ASTNestedNameElement(s.identOrOp, s.templateArgs)
265
- if s.declaration is not None:
266
- key.append((nne, s.templateParams, s.declaration.get_newest_id()))
267
- else:
268
- key.append((nne, s.templateParams, None))
335
+ key = [
336
+ (
337
+ ASTNestedNameElement(s.identOrOp, s.templateArgs),
338
+ s.templateParams,
339
+ None if s.declaration is None else s.declaration.get_newest_id(),
340
+ )
341
+ for s in reversed(symbols)
342
+ ]
269
343
  return LookupKey(key)
270
344
 
271
345
  def get_full_nested_name(self) -> ASTNestedName:
@@ -282,83 +356,100 @@ class Symbol:
282
356
  templates.append(False)
283
357
  return ASTNestedName(names, templates, rooted=False)
284
358
 
285
- def _find_first_named_symbol(self, identOrOp: ASTIdentifier | ASTOperator,
286
- templateParams: ASTTemplateParams | ASTTemplateIntroduction,
287
- templateArgs: ASTTemplateArgs | None,
288
- templateShorthand: bool, matchSelf: bool,
289
- recurseInAnon: bool, correctPrimaryTemplateArgs: bool,
290
- ) -> Symbol | None:
359
+ def _find_first_named_symbol(
360
+ self,
361
+ ident_or_op: ASTIdentifier | ASTOperator,
362
+ template_params: ASTTemplateParams | ASTTemplateIntroduction,
363
+ template_args: ASTTemplateArgs | None,
364
+ template_shorthand: bool,
365
+ match_self: bool,
366
+ recurse_in_anon: bool,
367
+ correct_primary_template_args: bool,
368
+ ) -> Symbol | None:
291
369
  if Symbol.debug_lookup:
292
- Symbol.debug_print("_find_first_named_symbol ->")
293
- res = self._find_named_symbols(identOrOp, templateParams, templateArgs,
294
- templateShorthand, matchSelf, recurseInAnon,
295
- correctPrimaryTemplateArgs,
296
- searchInSiblings=False)
370
+ Symbol.debug_print('_find_first_named_symbol ->')
371
+ res = self._find_named_symbols(
372
+ ident_or_op,
373
+ template_params,
374
+ template_args,
375
+ template_shorthand,
376
+ match_self,
377
+ recurse_in_anon,
378
+ correct_primary_template_args,
379
+ search_in_siblings=False,
380
+ )
297
381
  try:
298
382
  return next(res)
299
383
  except StopIteration:
300
384
  return None
301
385
 
302
- def _find_named_symbols(self, identOrOp: ASTIdentifier | ASTOperator,
303
- templateParams: ASTTemplateParams | ASTTemplateIntroduction,
304
- templateArgs: ASTTemplateArgs,
305
- templateShorthand: bool, matchSelf: bool,
306
- recurseInAnon: bool, correctPrimaryTemplateArgs: bool,
307
- searchInSiblings: bool) -> Iterator[Symbol]:
386
+ def _find_named_symbols(
387
+ self,
388
+ ident_or_op: ASTIdentifier | ASTOperator,
389
+ template_params: ASTTemplateParams | ASTTemplateIntroduction,
390
+ template_args: ASTTemplateArgs,
391
+ template_shorthand: bool,
392
+ match_self: bool,
393
+ recurse_in_anon: bool,
394
+ correct_primary_template_args: bool,
395
+ search_in_siblings: bool,
396
+ ) -> Iterator[Symbol]:
308
397
  if Symbol.debug_lookup:
309
398
  Symbol.debug_indent += 1
310
- Symbol.debug_print("_find_named_symbols:")
399
+ Symbol.debug_print('_find_named_symbols:')
311
400
  Symbol.debug_indent += 1
312
- Symbol.debug_print("self:")
313
- logger.debug(self.to_string(Symbol.debug_indent + 1), end="")
314
- Symbol.debug_print("identOrOp: ", identOrOp)
315
- Symbol.debug_print("templateParams: ", templateParams)
316
- Symbol.debug_print("templateArgs: ", templateArgs)
317
- Symbol.debug_print("templateShorthand: ", templateShorthand)
318
- Symbol.debug_print("matchSelf: ", matchSelf)
319
- Symbol.debug_print("recurseInAnon: ", recurseInAnon)
320
- Symbol.debug_print("correctPrimaryTemplateAargs:", correctPrimaryTemplateArgs)
321
- Symbol.debug_print("searchInSiblings: ", searchInSiblings)
322
-
323
- if correctPrimaryTemplateArgs:
324
- if templateParams is not None and templateArgs is not None:
401
+ Symbol.debug_print('self:')
402
+ logger.debug(self.to_string(Symbol.debug_indent + 1), end='')
403
+ Symbol.debug_print('ident_or_op: ', ident_or_op)
404
+ Symbol.debug_print('template_params: ', template_params)
405
+ Symbol.debug_print('template_args: ', template_args)
406
+ Symbol.debug_print('template_shorthand: ', template_shorthand)
407
+ Symbol.debug_print('match_self: ', match_self)
408
+ Symbol.debug_print('recurse_in_anon: ', recurse_in_anon)
409
+ Symbol.debug_print(
410
+ 'correct_primary_template_args:', correct_primary_template_args
411
+ )
412
+ Symbol.debug_print('search_in_siblings: ', search_in_siblings)
413
+
414
+ if correct_primary_template_args:
415
+ if template_params is not None and template_args is not None:
325
416
  # If both are given, but it's not a specialization, then do lookup as if
326
417
  # there is no argument list.
327
418
  # For example: template<typename T> int A<T>::var;
328
- if not _is_specialization(templateParams, templateArgs):
329
- templateArgs = None
419
+ if not _is_specialization(template_params, template_args):
420
+ template_args = None
330
421
 
331
422
  def matches(s: Symbol) -> bool:
332
- if s.identOrOp != identOrOp:
423
+ if s.identOrOp != ident_or_op:
333
424
  return False
334
- if (s.templateParams is None) != (templateParams is None):
335
- if templateParams is not None:
425
+ if (s.templateParams is None) != (template_params is None):
426
+ if template_params is not None:
336
427
  # we query with params, they must match params
337
428
  return False
338
- if not templateShorthand:
429
+ if not template_shorthand:
339
430
  # we don't query with params, and we do care about them
340
431
  return False
341
- if templateParams:
432
+ if template_params:
342
433
  # TODO: do better comparison
343
- if str(s.templateParams) != str(templateParams):
434
+ if str(s.templateParams) != str(template_params):
344
435
  return False
345
- if (s.templateArgs is None) != (templateArgs is None):
436
+ if (s.templateArgs is None) != (template_args is None):
346
437
  return False
347
438
  if s.templateArgs:
348
439
  # TODO: do better comparison
349
- if str(s.templateArgs) != str(templateArgs):
440
+ if str(s.templateArgs) != str(template_args):
350
441
  return False
351
442
  return True
352
443
 
353
444
  def candidates() -> Iterator[Symbol]:
354
445
  s = self
355
446
  if Symbol.debug_lookup:
356
- Symbol.debug_print("searching in self:")
357
- logger.debug(s.to_string(Symbol.debug_indent + 1), end="")
447
+ Symbol.debug_print('searching in self:')
448
+ logger.debug(s.to_string(Symbol.debug_indent + 1), end='')
358
449
  while True:
359
- if matchSelf:
450
+ if match_self:
360
451
  yield s
361
- if recurseInAnon:
452
+ if recurse_in_anon:
362
453
  yield from s.children_recurse_anon
363
454
  else:
364
455
  yield from s._children
@@ -367,17 +458,17 @@ class Symbol:
367
458
  break
368
459
  s = s.siblingAbove
369
460
  if Symbol.debug_lookup:
370
- Symbol.debug_print("searching in sibling:")
371
- logger.debug(s.to_string(Symbol.debug_indent + 1), end="")
461
+ Symbol.debug_print('searching in sibling:')
462
+ logger.debug(s.to_string(Symbol.debug_indent + 1), end='')
372
463
 
373
464
  for s in candidates():
374
465
  if Symbol.debug_lookup:
375
- Symbol.debug_print("candidate:")
376
- logger.debug(s.to_string(Symbol.debug_indent + 1), end="")
466
+ Symbol.debug_print('candidate:')
467
+ logger.debug(s.to_string(Symbol.debug_indent + 1), end='')
377
468
  if matches(s):
378
469
  if Symbol.debug_lookup:
379
470
  Symbol.debug_indent += 1
380
- Symbol.debug_print("matches")
471
+ Symbol.debug_print('matches')
381
472
  Symbol.debug_indent -= 3
382
473
  yield s
383
474
  if Symbol.debug_lookup:
@@ -387,143 +478,173 @@ class Symbol:
387
478
 
388
479
  def _symbol_lookup(
389
480
  self,
390
- nestedName: ASTNestedName,
391
- templateDecls: list[Any],
392
- onMissingQualifiedSymbol: Callable[
393
- [Symbol, ASTIdentifier | ASTOperator, Any, ASTTemplateArgs], Symbol | None,
481
+ nested_name: ASTNestedName,
482
+ template_decls: list[Any],
483
+ on_missing_qualified_symbol: Callable[
484
+ [Symbol, ASTIdentifier | ASTOperator, Any, ASTTemplateArgs],
485
+ Symbol | None,
394
486
  ],
395
- strictTemplateParamArgLists: bool, ancestorLookupType: str,
396
- templateShorthand: bool, matchSelf: bool,
397
- recurseInAnon: bool, correctPrimaryTemplateArgs: bool,
398
- searchInSiblings: bool,
399
- ) -> SymbolLookupResult:
400
- # ancestorLookupType: if not None, specifies the target type of the lookup
487
+ strict_template_param_arg_lists: bool,
488
+ ancestor_lookup_type: str,
489
+ template_shorthand: bool,
490
+ match_self: bool,
491
+ recurse_in_anon: bool,
492
+ correct_primary_template_args: bool,
493
+ search_in_siblings: bool,
494
+ ) -> SymbolLookupResult | None:
495
+ # ancestor_lookup_type: if not None, specifies the target type of the lookup
401
496
  if Symbol.debug_lookup:
402
497
  Symbol.debug_indent += 1
403
- Symbol.debug_print("_symbol_lookup:")
498
+ Symbol.debug_print('_symbol_lookup:')
404
499
  Symbol.debug_indent += 1
405
- Symbol.debug_print("self:")
406
- logger.debug(self.to_string(Symbol.debug_indent + 1), end="")
407
- Symbol.debug_print("nestedName: ", nestedName)
408
- Symbol.debug_print("templateDecls: ", ",".join(str(t) for t in templateDecls))
409
- Symbol.debug_print("strictTemplateParamArgLists:", strictTemplateParamArgLists)
410
- Symbol.debug_print("ancestorLookupType:", ancestorLookupType)
411
- Symbol.debug_print("templateShorthand: ", templateShorthand)
412
- Symbol.debug_print("matchSelf: ", matchSelf)
413
- Symbol.debug_print("recurseInAnon: ", recurseInAnon)
414
- Symbol.debug_print("correctPrimaryTemplateArgs: ", correctPrimaryTemplateArgs)
415
- Symbol.debug_print("searchInSiblings: ", searchInSiblings)
416
-
417
- if strictTemplateParamArgLists:
500
+ Symbol.debug_print('self:')
501
+ logger.debug(self.to_string(Symbol.debug_indent + 1), end='')
502
+ Symbol.debug_print('nested_name: ', nested_name)
503
+ Symbol.debug_print(
504
+ 'template_decls: ', ','.join(str(t) for t in template_decls)
505
+ )
506
+ Symbol.debug_print(
507
+ 'strict_template_param_arg_lists:', strict_template_param_arg_lists
508
+ )
509
+ Symbol.debug_print('ancestor_lookup_type:', ancestor_lookup_type)
510
+ Symbol.debug_print('template_shorthand: ', template_shorthand)
511
+ Symbol.debug_print('match_self: ', match_self)
512
+ Symbol.debug_print('recurse_in_anon: ', recurse_in_anon)
513
+ Symbol.debug_print(
514
+ 'correct_primary_template_args: ', correct_primary_template_args
515
+ )
516
+ Symbol.debug_print('search_in_siblings: ', search_in_siblings)
517
+
518
+ if strict_template_param_arg_lists:
418
519
  # Each template argument list must have a template parameter list.
419
520
  # But to declare a template there must be an additional template parameter list.
420
- assert (nestedName.num_templates() == len(templateDecls) or
421
- nestedName.num_templates() + 1 == len(templateDecls))
521
+ num_nested_templates = nested_name.num_templates()
522
+ num_template_decls = len(template_decls)
523
+ assert (
524
+ num_nested_templates == num_template_decls
525
+ or num_nested_templates + 1 == num_template_decls
526
+ )
422
527
  else:
423
- assert len(templateDecls) <= nestedName.num_templates() + 1
528
+ assert len(template_decls) <= nested_name.num_templates() + 1
424
529
 
425
- names = nestedName.names
530
+ names = nested_name.names
426
531
 
427
532
  # find the right starting point for lookup
428
- parentSymbol = self
429
- if nestedName.rooted:
430
- while parentSymbol.parent:
431
- parentSymbol = parentSymbol.parent
432
- if ancestorLookupType is not None:
533
+ parent_symbol = self
534
+ if nested_name.rooted:
535
+ while parent_symbol.parent:
536
+ parent_symbol = parent_symbol.parent
537
+ if ancestor_lookup_type is not None:
433
538
  # walk up until we find the first identifier
434
- firstName = names[0]
435
- if not firstName.is_operator():
436
- while parentSymbol.parent:
437
- if parentSymbol.find_identifier(firstName.identOrOp,
438
- matchSelf=matchSelf,
439
- recurseInAnon=recurseInAnon,
440
- searchInSiblings=searchInSiblings):
539
+ first_name = names[0]
540
+ if not first_name.is_operator():
541
+ while parent_symbol.parent:
542
+ if parent_symbol.find_identifier(
543
+ first_name.identOrOp,
544
+ matchSelf=match_self,
545
+ recurseInAnon=recurse_in_anon,
546
+ searchInSiblings=search_in_siblings,
547
+ ):
441
548
  # if we are in the scope of a constructor but wants to
442
549
  # reference the class we need to walk one extra up
443
- if (len(names) == 1 and ancestorLookupType == 'class' and matchSelf and
444
- parentSymbol.parent and
445
- parentSymbol.parent.identOrOp == firstName.identOrOp):
550
+ if (
551
+ len(names) == 1
552
+ and ancestor_lookup_type == 'class'
553
+ and match_self
554
+ and parent_symbol.parent
555
+ and parent_symbol.parent.identOrOp == first_name.identOrOp
556
+ ):
446
557
  pass
447
558
  else:
448
559
  break
449
- parentSymbol = parentSymbol.parent
560
+ parent_symbol = parent_symbol.parent
450
561
 
451
562
  if Symbol.debug_lookup:
452
- Symbol.debug_print("starting point:")
453
- logger.debug(parentSymbol.to_string(Symbol.debug_indent + 1), end="")
563
+ Symbol.debug_print('starting point:')
564
+ logger.debug(parent_symbol.to_string(Symbol.debug_indent + 1), end='')
454
565
 
455
566
  # and now the actual lookup
456
- iTemplateDecl = 0
567
+ i_template_decl = 0
457
568
  for name in names[:-1]:
458
- identOrOp = name.identOrOp
459
- templateArgs = name.templateArgs
460
- if strictTemplateParamArgLists:
569
+ ident_or_op = name.identOrOp
570
+ template_args = name.templateArgs
571
+ if strict_template_param_arg_lists:
461
572
  # there must be a parameter list
462
- if templateArgs:
463
- assert iTemplateDecl < len(templateDecls)
464
- templateParams = templateDecls[iTemplateDecl]
465
- iTemplateDecl += 1
573
+ if template_args:
574
+ assert i_template_decl < len(template_decls)
575
+ template_params = template_decls[i_template_decl]
576
+ i_template_decl += 1
466
577
  else:
467
- templateParams = None
578
+ template_params = None
468
579
  else:
469
580
  # take the next template parameter list if there is one
470
581
  # otherwise it's ok
471
- if templateArgs and iTemplateDecl < len(templateDecls):
472
- templateParams = templateDecls[iTemplateDecl]
473
- iTemplateDecl += 1
582
+ if template_args and i_template_decl < len(template_decls):
583
+ template_params = template_decls[i_template_decl]
584
+ i_template_decl += 1
474
585
  else:
475
- templateParams = None
476
-
477
- symbol = parentSymbol._find_first_named_symbol(
478
- identOrOp,
479
- templateParams, templateArgs,
480
- templateShorthand=templateShorthand,
481
- matchSelf=matchSelf,
482
- recurseInAnon=recurseInAnon,
483
- correctPrimaryTemplateArgs=correctPrimaryTemplateArgs)
586
+ template_params = None
587
+
588
+ symbol = parent_symbol._find_first_named_symbol(
589
+ ident_or_op,
590
+ template_params,
591
+ template_args,
592
+ template_shorthand=template_shorthand,
593
+ match_self=match_self,
594
+ recurse_in_anon=recurse_in_anon,
595
+ correct_primary_template_args=correct_primary_template_args,
596
+ )
484
597
  if symbol is None:
485
- symbol = onMissingQualifiedSymbol(parentSymbol, identOrOp,
486
- templateParams, templateArgs)
598
+ symbol = on_missing_qualified_symbol(
599
+ parent_symbol, ident_or_op, template_params, template_args
600
+ )
487
601
  if symbol is None:
488
602
  if Symbol.debug_lookup:
489
603
  Symbol.debug_indent -= 2
490
604
  return None
491
605
  # We have now matched part of a nested name, and need to match more
492
- # so even if we should matchSelf before, we definitely shouldn't
493
- # even more. (see also issue #2666)
494
- matchSelf = False
495
- parentSymbol = symbol
606
+ # so even if we should match_self before, we definitely shouldn't
607
+ # even more.
608
+ # See: https://github.com/sphinx-doc/sphinx/issues/2666
609
+ match_self = False
610
+ parent_symbol = symbol
496
611
 
497
612
  if Symbol.debug_lookup:
498
- Symbol.debug_print("handle last name from:")
499
- logger.debug(parentSymbol.to_string(Symbol.debug_indent + 1), end="")
613
+ Symbol.debug_print('handle last name from:')
614
+ logger.debug(parent_symbol.to_string(Symbol.debug_indent + 1), end='')
500
615
 
501
616
  # handle the last name
502
617
  name = names[-1]
503
- identOrOp = name.identOrOp
504
- templateArgs = name.templateArgs
505
- if iTemplateDecl < len(templateDecls):
506
- assert iTemplateDecl + 1 == len(templateDecls)
507
- templateParams = templateDecls[iTemplateDecl]
618
+ ident_or_op = name.identOrOp
619
+ template_args = name.templateArgs
620
+ if i_template_decl < len(template_decls):
621
+ assert i_template_decl + 1 == len(template_decls)
622
+ template_params = template_decls[i_template_decl]
508
623
  else:
509
- assert iTemplateDecl == len(templateDecls)
510
- templateParams = None
511
-
512
- symbols = parentSymbol._find_named_symbols(
513
- identOrOp, templateParams, templateArgs,
514
- templateShorthand=templateShorthand, matchSelf=matchSelf,
515
- recurseInAnon=recurseInAnon, correctPrimaryTemplateArgs=False,
516
- searchInSiblings=searchInSiblings)
624
+ assert i_template_decl == len(template_decls)
625
+ template_params = None
626
+
627
+ symbols = parent_symbol._find_named_symbols(
628
+ ident_or_op,
629
+ template_params,
630
+ template_args,
631
+ template_shorthand=template_shorthand,
632
+ match_self=match_self,
633
+ recurse_in_anon=recurse_in_anon,
634
+ correct_primary_template_args=False,
635
+ search_in_siblings=search_in_siblings,
636
+ )
517
637
  if Symbol.debug_lookup:
518
638
  symbols = list(symbols) # type: ignore[assignment]
519
639
  Symbol.debug_indent -= 2
520
- return SymbolLookupResult(symbols, parentSymbol,
521
- identOrOp, templateParams, templateArgs)
640
+ return SymbolLookupResult(
641
+ symbols, parent_symbol, ident_or_op, template_params, template_args
642
+ )
522
643
 
523
644
  def _add_symbols(
524
645
  self,
525
- nestedName: ASTNestedName,
526
- templateDecls: list[Any],
646
+ nested_name: ASTNestedName,
647
+ template_decls: list[Any],
527
648
  declaration: ASTDeclaration | None,
528
649
  docname: str | None,
529
650
  line: int | None,
@@ -533,175 +654,195 @@ class Symbol:
533
654
 
534
655
  if Symbol.debug_lookup:
535
656
  Symbol.debug_indent += 1
536
- Symbol.debug_print("_add_symbols:")
657
+ Symbol.debug_print('_add_symbols:')
537
658
  Symbol.debug_indent += 1
538
- Symbol.debug_print("tdecls:", ",".join(str(t) for t in templateDecls))
539
- Symbol.debug_print("nn: ", nestedName)
540
- Symbol.debug_print("decl: ", declaration)
541
- Symbol.debug_print(f"location: {docname}:{line}")
542
-
543
- def onMissingQualifiedSymbol(parentSymbol: Symbol,
544
- identOrOp: ASTIdentifier | ASTOperator,
545
- templateParams: Any, templateArgs: ASTTemplateArgs,
546
- ) -> Symbol | None:
659
+ Symbol.debug_print('tdecls:', ','.join(str(t) for t in template_decls))
660
+ Symbol.debug_print('nn: ', nested_name)
661
+ Symbol.debug_print('decl: ', declaration)
662
+ Symbol.debug_print(f'location: {docname}:{line}')
663
+
664
+ def on_missing_qualified_symbol(
665
+ parent_symbol: Symbol,
666
+ ident_or_op: ASTIdentifier | ASTOperator,
667
+ template_params: Any,
668
+ template_args: ASTTemplateArgs,
669
+ ) -> Symbol | None:
547
670
  if Symbol.debug_lookup:
548
671
  Symbol.debug_indent += 1
549
- Symbol.debug_print("_add_symbols, onMissingQualifiedSymbol:")
672
+ Symbol.debug_print('_add_symbols, on_missing_qualified_symbol:')
550
673
  Symbol.debug_indent += 1
551
- Symbol.debug_print("templateParams:", templateParams)
552
- Symbol.debug_print("identOrOp: ", identOrOp)
553
- Symbol.debug_print("templateARgs: ", templateArgs)
674
+ Symbol.debug_print('template_params:', template_params)
675
+ Symbol.debug_print('ident_or_op: ', ident_or_op)
676
+ Symbol.debug_print('template_args: ', template_args)
554
677
  Symbol.debug_indent -= 2
555
- return Symbol(parent=parentSymbol, identOrOp=identOrOp,
556
- templateParams=templateParams,
557
- templateArgs=templateArgs, declaration=None,
558
- docname=None, line=None)
559
-
560
- lookupResult = self._symbol_lookup(nestedName, templateDecls,
561
- onMissingQualifiedSymbol,
562
- strictTemplateParamArgLists=True,
563
- ancestorLookupType=None,
564
- templateShorthand=False,
565
- matchSelf=False,
566
- recurseInAnon=False,
567
- correctPrimaryTemplateArgs=True,
568
- searchInSiblings=False)
569
- assert lookupResult is not None # we create symbols all the way, so that can't happen
570
- symbols = list(lookupResult.symbols)
678
+ return Symbol(
679
+ parent=parent_symbol,
680
+ identOrOp=ident_or_op,
681
+ templateParams=template_params,
682
+ templateArgs=template_args,
683
+ declaration=None,
684
+ docname=None,
685
+ line=None,
686
+ )
687
+
688
+ lookup_result = self._symbol_lookup(
689
+ nested_name,
690
+ template_decls,
691
+ on_missing_qualified_symbol,
692
+ strict_template_param_arg_lists=True,
693
+ ancestor_lookup_type=None,
694
+ template_shorthand=False,
695
+ match_self=False,
696
+ recurse_in_anon=False,
697
+ correct_primary_template_args=True,
698
+ search_in_siblings=False,
699
+ )
700
+ # we create symbols all the way, so that can't happen
701
+ assert lookup_result is not None
702
+ symbols = list(lookup_result.symbols)
571
703
  if len(symbols) == 0:
572
704
  if Symbol.debug_lookup:
573
- Symbol.debug_print("_add_symbols, result, no symbol:")
705
+ Symbol.debug_print('_add_symbols, result, no symbol:')
574
706
  Symbol.debug_indent += 1
575
- Symbol.debug_print("templateParams:", lookupResult.templateParams)
576
- Symbol.debug_print("identOrOp: ", lookupResult.identOrOp)
577
- Symbol.debug_print("templateArgs: ", lookupResult.templateArgs)
578
- Symbol.debug_print("declaration: ", declaration)
579
- Symbol.debug_print(f"location: {docname}:{line}")
707
+ Symbol.debug_print('template_params:', lookup_result.template_params)
708
+ Symbol.debug_print('ident_or_op: ', lookup_result.ident_or_op)
709
+ Symbol.debug_print('template_args: ', lookup_result.template_args)
710
+ Symbol.debug_print('declaration: ', declaration)
711
+ Symbol.debug_print(f'location: {docname}:{line}')
580
712
  Symbol.debug_indent -= 1
581
- symbol = Symbol(parent=lookupResult.parentSymbol,
582
- identOrOp=lookupResult.identOrOp,
583
- templateParams=lookupResult.templateParams,
584
- templateArgs=lookupResult.templateArgs,
585
- declaration=declaration,
586
- docname=docname, line=line)
713
+ symbol = Symbol(
714
+ parent=lookup_result.parent_symbol,
715
+ identOrOp=lookup_result.ident_or_op,
716
+ templateParams=lookup_result.template_params,
717
+ templateArgs=lookup_result.template_args,
718
+ declaration=declaration,
719
+ docname=docname,
720
+ line=line,
721
+ )
587
722
  if Symbol.debug_lookup:
588
723
  Symbol.debug_indent -= 2
589
724
  return symbol
590
725
 
591
726
  if Symbol.debug_lookup:
592
- Symbol.debug_print("_add_symbols, result, symbols:")
727
+ Symbol.debug_print('_add_symbols, result, symbols:')
593
728
  Symbol.debug_indent += 1
594
- Symbol.debug_print("number symbols:", len(symbols))
729
+ Symbol.debug_print('number symbols:', len(symbols))
595
730
  Symbol.debug_indent -= 1
596
731
 
597
732
  if not declaration:
598
733
  if Symbol.debug_lookup:
599
- Symbol.debug_print("no declaration")
734
+ Symbol.debug_print('no declaration')
600
735
  Symbol.debug_indent -= 2
601
736
  # good, just a scope creation
602
737
  # TODO: what if we have more than one symbol?
603
738
  return symbols[0]
604
739
 
605
- noDecl = []
606
- withDecl = []
607
- dupDecl = []
740
+ no_decl = []
741
+ with_decl = []
742
+ dup_decl = []
608
743
  for s in symbols:
609
744
  if s.declaration is None:
610
- noDecl.append(s)
745
+ no_decl.append(s)
611
746
  elif s.isRedeclaration:
612
- dupDecl.append(s)
747
+ dup_decl.append(s)
613
748
  else:
614
- withDecl.append(s)
749
+ with_decl.append(s)
615
750
  if Symbol.debug_lookup:
616
- Symbol.debug_print("#noDecl: ", len(noDecl))
617
- Symbol.debug_print("#withDecl:", len(withDecl))
618
- Symbol.debug_print("#dupDecl: ", len(dupDecl))
751
+ Symbol.debug_print('#no_decl: ', len(no_decl))
752
+ Symbol.debug_print('#with_decl:', len(with_decl))
753
+ Symbol.debug_print('#dup_decl: ', len(dup_decl))
619
754
  # With partial builds we may start with a large symbol tree stripped of declarations.
620
- # Essentially any combination of noDecl, withDecl, and dupDecls seems possible.
755
+ # Essentially any combination of no_decl, with_decl, and dup_decls seems possible.
621
756
  # TODO: make partial builds fully work. What should happen when the primary symbol gets
622
757
  # deleted, and other duplicates exist? The full document should probably be rebuild.
623
758
 
624
759
  # First check if one of those with a declaration matches.
625
760
  # If it's a function, we need to compare IDs,
626
761
  # otherwise there should be only one symbol with a declaration.
627
- def makeCandSymbol() -> Symbol:
762
+ def make_cand_symbol() -> Symbol:
628
763
  if Symbol.debug_lookup:
629
- Symbol.debug_print("begin: creating candidate symbol")
630
- symbol = Symbol(parent=lookupResult.parentSymbol,
631
- identOrOp=lookupResult.identOrOp,
632
- templateParams=lookupResult.templateParams,
633
- templateArgs=lookupResult.templateArgs,
634
- declaration=declaration,
635
- docname=docname, line=line)
764
+ Symbol.debug_print('begin: creating candidate symbol')
765
+ symbol = Symbol(
766
+ parent=lookup_result.parent_symbol,
767
+ identOrOp=lookup_result.ident_or_op,
768
+ templateParams=lookup_result.template_params,
769
+ templateArgs=lookup_result.template_args,
770
+ declaration=declaration,
771
+ docname=docname,
772
+ line=line,
773
+ )
636
774
  if Symbol.debug_lookup:
637
- Symbol.debug_print("end: creating candidate symbol")
775
+ Symbol.debug_print('end: creating candidate symbol')
638
776
  return symbol
639
- if len(withDecl) == 0:
640
- candSymbol = None
777
+
778
+ if len(with_decl) == 0:
779
+ cand_symbol = None
641
780
  else:
642
- candSymbol = makeCandSymbol()
781
+ cand_symbol = make_cand_symbol()
643
782
 
644
- def handleDuplicateDeclaration(symbol: Symbol, candSymbol: Symbol) -> None:
783
+ def handle_duplicate_declaration(
784
+ symbol: Symbol, cand_symbol: Symbol
785
+ ) -> None:
645
786
  if Symbol.debug_lookup:
646
787
  Symbol.debug_indent += 1
647
- Symbol.debug_print("redeclaration")
788
+ Symbol.debug_print('redeclaration')
648
789
  Symbol.debug_indent -= 1
649
790
  Symbol.debug_indent -= 2
650
791
  # Redeclaration of the same symbol.
651
792
  # Let the new one be there, but raise an error to the client
652
793
  # so it can use the real symbol as subscope.
653
794
  # This will probably result in a duplicate id warning.
654
- candSymbol.isRedeclaration = True
795
+ cand_symbol.isRedeclaration = True
655
796
  raise _DuplicateSymbolError(symbol, declaration)
656
797
 
657
- if declaration.objectType != "function":
658
- assert len(withDecl) <= 1
659
- handleDuplicateDeclaration(withDecl[0], candSymbol)
798
+ if declaration.objectType != 'function':
799
+ assert len(with_decl) <= 1
800
+ handle_duplicate_declaration(with_decl[0], cand_symbol)
660
801
  # (not reachable)
661
802
 
662
803
  # a function, so compare IDs
663
- candId = declaration.get_newest_id()
804
+ cand_id = declaration.get_newest_id()
664
805
  if Symbol.debug_lookup:
665
- Symbol.debug_print("candId:", candId)
666
- for symbol in withDecl:
806
+ Symbol.debug_print('cand_id:', cand_id)
807
+ for symbol in with_decl:
667
808
  # but all existing must be functions as well,
668
809
  # otherwise we declare it to be a duplicate
669
810
  if symbol.declaration.objectType != 'function':
670
- handleDuplicateDeclaration(symbol, candSymbol)
811
+ handle_duplicate_declaration(symbol, cand_symbol)
671
812
  # (not reachable)
672
- oldId = symbol.declaration.get_newest_id()
813
+ old_id = symbol.declaration.get_newest_id()
673
814
  if Symbol.debug_lookup:
674
- Symbol.debug_print("oldId: ", oldId)
675
- if candId == oldId:
676
- handleDuplicateDeclaration(symbol, candSymbol)
815
+ Symbol.debug_print('old_id: ', old_id)
816
+ if cand_id == old_id:
817
+ handle_duplicate_declaration(symbol, cand_symbol)
677
818
  # (not reachable)
678
819
  # no candidate symbol found with matching ID
679
820
  # if there is an empty symbol, fill that one
680
- if len(noDecl) == 0:
821
+ if len(no_decl) == 0:
681
822
  if Symbol.debug_lookup:
682
- Symbol.debug_print("no match, no empty")
683
- if candSymbol is not None:
684
- Symbol.debug_print("result is already created candSymbol")
823
+ Symbol.debug_print('no match, no empty')
824
+ if cand_symbol is not None:
825
+ Symbol.debug_print('result is already created cand_symbol')
685
826
  else:
686
- Symbol.debug_print("result is makeCandSymbol()")
827
+ Symbol.debug_print('result is make_cand_symbol()')
687
828
  Symbol.debug_indent -= 2
688
- if candSymbol is not None:
689
- return candSymbol
829
+ if cand_symbol is not None:
830
+ return cand_symbol
690
831
  else:
691
- return makeCandSymbol()
832
+ return make_cand_symbol()
692
833
  else:
693
834
  if Symbol.debug_lookup:
694
835
  Symbol.debug_print(
695
- "no match, but fill an empty declaration, candSybmol is not None?:",
696
- candSymbol is not None,
836
+ 'no match, but fill an empty declaration, cand_sybmol is not None?:',
837
+ cand_symbol is not None,
697
838
  )
698
839
  Symbol.debug_indent -= 2
699
- if candSymbol is not None:
700
- candSymbol.remove()
701
- # assert len(noDecl) == 1
840
+ if cand_symbol is not None:
841
+ cand_symbol.remove()
842
+ # assert len(no_decl) == 1
702
843
  # TODO: enable assertion when we at some point find out how to do cleanup
703
844
  # for now, just take the first one, it should work fine ... right?
704
- symbol = noDecl[0]
845
+ symbol = no_decl[0]
705
846
  # If someone first opened the scope, and then later
706
847
  # declares it, e.g,
707
848
  # .. namespace:: Test
@@ -710,98 +851,118 @@ class Symbol:
710
851
  symbol._fill_empty(declaration, docname, line)
711
852
  return symbol
712
853
 
713
- def merge_with(self, other: Symbol, docnames: list[str],
714
- env: BuildEnvironment) -> None:
854
+ def merge_with(
855
+ self, other: Symbol, docnames: list[str], env: BuildEnvironment
856
+ ) -> None:
715
857
  if Symbol.debug_lookup:
716
858
  Symbol.debug_indent += 1
717
- Symbol.debug_print("merge_with:")
859
+ Symbol.debug_print('merge_with:')
718
860
  assert other is not None
719
861
 
720
- def unconditionalAdd(self: Symbol, otherChild: Symbol) -> None:
862
+ def unconditional_add(self: Symbol, other_child: Symbol) -> None:
721
863
  # TODO: hmm, should we prune by docnames?
722
- self._children.append(otherChild)
723
- otherChild.parent = self
724
- otherChild._assert_invariants()
864
+ self._children.append(other_child)
865
+ other_child.parent = self
866
+ other_child._assert_invariants()
725
867
 
726
868
  if Symbol.debug_lookup:
727
869
  Symbol.debug_indent += 1
728
- for otherChild in other._children:
870
+ for other_child in other._children:
729
871
  if Symbol.debug_lookup:
730
- Symbol.debug_print("otherChild:\n", otherChild.to_string(Symbol.debug_indent))
872
+ Symbol.debug_print(
873
+ 'other_child:\n', other_child.to_string(Symbol.debug_indent)
874
+ )
731
875
  Symbol.debug_indent += 1
732
- if otherChild.isRedeclaration:
733
- unconditionalAdd(self, otherChild)
876
+ if other_child.isRedeclaration:
877
+ unconditional_add(self, other_child)
734
878
  if Symbol.debug_lookup:
735
- Symbol.debug_print("isRedeclaration")
879
+ Symbol.debug_print('is_redeclaration')
736
880
  Symbol.debug_indent -= 1
737
881
  continue
738
- candiateIter = self._find_named_symbols(
739
- identOrOp=otherChild.identOrOp,
740
- templateParams=otherChild.templateParams,
741
- templateArgs=otherChild.templateArgs,
742
- templateShorthand=False, matchSelf=False,
743
- recurseInAnon=False, correctPrimaryTemplateArgs=False,
744
- searchInSiblings=False)
745
- candidates = list(candiateIter)
882
+ candiate_iter = self._find_named_symbols(
883
+ ident_or_op=other_child.identOrOp,
884
+ template_params=other_child.templateParams,
885
+ template_args=other_child.templateArgs,
886
+ template_shorthand=False,
887
+ match_self=False,
888
+ recurse_in_anon=False,
889
+ correct_primary_template_args=False,
890
+ search_in_siblings=False,
891
+ )
892
+ candidates = list(candiate_iter)
746
893
 
747
894
  if Symbol.debug_lookup:
748
- Symbol.debug_print("raw candidate symbols:", len(candidates))
895
+ Symbol.debug_print('raw candidate symbols:', len(candidates))
749
896
  symbols = [s for s in candidates if not s.isRedeclaration]
750
897
  if Symbol.debug_lookup:
751
- Symbol.debug_print("non-duplicate candidate symbols:", len(symbols))
898
+ Symbol.debug_print('non-duplicate candidate symbols:', len(symbols))
752
899
 
753
900
  if len(symbols) == 0:
754
- unconditionalAdd(self, otherChild)
901
+ unconditional_add(self, other_child)
755
902
  if Symbol.debug_lookup:
756
903
  Symbol.debug_indent -= 1
757
904
  continue
758
905
 
759
- ourChild = None
760
- if otherChild.declaration is None:
906
+ our_child = None
907
+ if other_child.declaration is None:
761
908
  if Symbol.debug_lookup:
762
- Symbol.debug_print("no declaration in other child")
763
- ourChild = symbols[0]
909
+ Symbol.debug_print('no declaration in other child')
910
+ our_child = symbols[0]
764
911
  else:
765
- queryId = otherChild.declaration.get_newest_id()
912
+ query_id = other_child.declaration.get_newest_id()
766
913
  if Symbol.debug_lookup:
767
- Symbol.debug_print("queryId: ", queryId)
914
+ Symbol.debug_print('query_id: ', query_id)
768
915
  for symbol in symbols:
769
916
  if symbol.declaration is None:
770
917
  if Symbol.debug_lookup:
771
- Symbol.debug_print("empty candidate")
918
+ Symbol.debug_print('empty candidate')
772
919
  # if in the end we have non-matching, but have an empty one,
773
920
  # then just continue with that
774
- ourChild = symbol
921
+ our_child = symbol
775
922
  continue
776
- candId = symbol.declaration.get_newest_id()
923
+ cand_id = symbol.declaration.get_newest_id()
777
924
  if Symbol.debug_lookup:
778
- Symbol.debug_print("candidate:", candId)
779
- if candId == queryId:
780
- ourChild = symbol
925
+ Symbol.debug_print('candidate:', cand_id)
926
+ if cand_id == query_id:
927
+ our_child = symbol
781
928
  break
782
929
  if Symbol.debug_lookup:
783
930
  Symbol.debug_indent -= 1
784
- if ourChild is None:
785
- unconditionalAdd(self, otherChild)
931
+ if our_child is None:
932
+ unconditional_add(self, other_child)
786
933
  continue
787
- if otherChild.declaration and otherChild.docname in docnames:
788
- if not ourChild.declaration:
789
- ourChild._fill_empty(otherChild.declaration,
790
- otherChild.docname, otherChild.line)
791
- elif ourChild.docname != otherChild.docname:
792
- name = str(ourChild.declaration)
793
- msg = __("Duplicate C++ declaration, also defined at %s:%s.\n"
794
- "Declaration is '.. cpp:%s:: %s'.")
795
- msg = msg % (ourChild.docname, ourChild.line,
796
- ourChild.declaration.directiveType, name)
797
- logger.warning(msg, location=(otherChild.docname, otherChild.line))
934
+ if other_child.declaration and other_child.docname in docnames:
935
+ if not our_child.declaration:
936
+ our_child._fill_empty(
937
+ other_child.declaration, other_child.docname, other_child.line
938
+ )
939
+ elif our_child.docname != other_child.docname:
940
+ name = str(our_child.declaration)
941
+ msg = __(
942
+ 'Duplicate C++ declaration, also defined at %s:%s.\n'
943
+ "Declaration is '.. cpp:%s:: %s'."
944
+ )
945
+ logger.warning(
946
+ msg,
947
+ our_child.docname,
948
+ our_child.line,
949
+ our_child.declaration.directiveType,
950
+ name,
951
+ location=(other_child.docname, other_child.line),
952
+ type='duplicate_declaration',
953
+ subtype='cpp',
954
+ )
798
955
  else:
799
- if (otherChild.declaration.objectType ==
800
- ourChild.declaration.objectType and
801
- otherChild.declaration.objectType in
802
- ('templateParam', 'functionParam') and
803
- ourChild.parent.declaration == otherChild.parent.declaration):
804
- # `ourChild` was just created during merging by the call
956
+ our_object_type = our_child.declaration.objectType
957
+ other_object_type = other_child.declaration.objectType
958
+ our_child_parent_decl = our_child.parent.declaration
959
+ other_child_parent_decl = other_child.parent.declaration
960
+ if (
961
+ other_object_type == our_object_type
962
+ and other_object_type in {'templateParam', 'functionParam'}
963
+ and our_child_parent_decl == other_child_parent_decl
964
+ ):
965
+ # `our_child` was just created during merging by the call
805
966
  # to `_fill_empty` on the parent and can be ignored.
806
967
  pass
807
968
  else:
@@ -809,70 +970,82 @@ class Symbol:
809
970
  # This can apparently happen, it should be safe to
810
971
  # just ignore it, right?
811
972
  # Hmm, only on duplicate declarations, right?
812
- msg = "Internal C++ domain error during symbol merging.\n"
813
- msg += "ourChild:\n" + ourChild.to_string(1)
814
- msg += "\notherChild:\n" + otherChild.to_string(1)
815
- logger.warning(msg, location=otherChild.docname)
816
- ourChild.merge_with(otherChild, docnames, env)
973
+ msg = 'Internal C++ domain error during symbol merging.\n'
974
+ msg += 'our_child:\n' + our_child.to_string(1)
975
+ msg += '\nother_child:\n' + other_child.to_string(1)
976
+ logger.warning(msg, location=other_child.docname)
977
+ our_child.merge_with(other_child, docnames, env)
817
978
  if Symbol.debug_lookup:
818
979
  Symbol.debug_indent -= 2
819
980
 
820
- def add_name(self, nestedName: ASTNestedName,
821
- templatePrefix: ASTTemplateDeclarationPrefix | None = None) -> Symbol:
981
+ def add_name(
982
+ self,
983
+ nestedName: ASTNestedName,
984
+ templatePrefix: ASTTemplateDeclarationPrefix | None = None,
985
+ ) -> Symbol:
822
986
  if Symbol.debug_lookup:
823
987
  Symbol.debug_indent += 1
824
- Symbol.debug_print("add_name:")
988
+ Symbol.debug_print('add_name:')
825
989
  if templatePrefix:
826
- templateDecls = templatePrefix.templates
990
+ template_decls = templatePrefix.templates
827
991
  else:
828
- templateDecls = []
829
- res = self._add_symbols(nestedName, templateDecls,
830
- declaration=None, docname=None, line=None)
992
+ template_decls = []
993
+ res = self._add_symbols(
994
+ nestedName, template_decls, declaration=None, docname=None, line=None
995
+ )
831
996
  if Symbol.debug_lookup:
832
997
  Symbol.debug_indent -= 1
833
998
  return res
834
999
 
835
- def add_declaration(self, declaration: ASTDeclaration,
836
- docname: str, line: int) -> Symbol:
1000
+ def add_declaration(
1001
+ self, declaration: ASTDeclaration, docname: str, line: int
1002
+ ) -> Symbol:
837
1003
  if Symbol.debug_lookup:
838
1004
  Symbol.debug_indent += 1
839
- Symbol.debug_print("add_declaration:")
1005
+ Symbol.debug_print('add_declaration:')
840
1006
  assert declaration is not None
841
1007
  assert docname is not None
842
1008
  assert line is not None
843
- nestedName = declaration.name
1009
+ nested_name = declaration.name
844
1010
  if declaration.templatePrefix:
845
- templateDecls = declaration.templatePrefix.templates
1011
+ template_decls = declaration.templatePrefix.templates
846
1012
  else:
847
- templateDecls = []
848
- res = self._add_symbols(nestedName, templateDecls, declaration, docname, line)
1013
+ template_decls = []
1014
+ res = self._add_symbols(nested_name, template_decls, declaration, docname, line)
849
1015
  if Symbol.debug_lookup:
850
1016
  Symbol.debug_indent -= 1
851
1017
  return res
852
1018
 
853
- def find_identifier(self, identOrOp: ASTIdentifier | ASTOperator,
854
- matchSelf: bool, recurseInAnon: bool, searchInSiblings: bool,
855
- ) -> Symbol | None:
1019
+ def find_identifier(
1020
+ self,
1021
+ identOrOp: ASTIdentifier | ASTOperator,
1022
+ matchSelf: bool,
1023
+ recurseInAnon: bool,
1024
+ searchInSiblings: bool,
1025
+ ) -> Symbol | None:
856
1026
  if Symbol.debug_lookup:
857
1027
  Symbol.debug_indent += 1
858
- Symbol.debug_print("find_identifier:")
1028
+ Symbol.debug_print('find_identifier:')
859
1029
  Symbol.debug_indent += 1
860
- Symbol.debug_print("identOrOp: ", identOrOp)
861
- Symbol.debug_print("matchSelf: ", matchSelf)
862
- Symbol.debug_print("recurseInAnon: ", recurseInAnon)
863
- Symbol.debug_print("searchInSiblings:", searchInSiblings)
864
- logger.debug(self.to_string(Symbol.debug_indent + 1), end="")
1030
+ Symbol.debug_print('identOrOp: ', identOrOp)
1031
+ Symbol.debug_print('matchSelf: ', matchSelf)
1032
+ Symbol.debug_print('recurseInAnon: ', recurseInAnon)
1033
+ Symbol.debug_print('searchInSiblings:', searchInSiblings)
1034
+ logger.debug(self.to_string(Symbol.debug_indent + 1), end='')
865
1035
  Symbol.debug_indent -= 2
866
1036
  current = self
867
1037
  while current is not None:
868
1038
  if Symbol.debug_lookup:
869
1039
  Symbol.debug_indent += 2
870
- Symbol.debug_print("trying:")
871
- logger.debug(current.to_string(Symbol.debug_indent + 1), end="")
1040
+ Symbol.debug_print('trying:')
1041
+ logger.debug(current.to_string(Symbol.debug_indent + 1), end='')
872
1042
  Symbol.debug_indent -= 2
873
1043
  if matchSelf and current.identOrOp == identOrOp:
874
1044
  return current
875
- children = current.children_recurse_anon if recurseInAnon else current._children
1045
+ if recurseInAnon:
1046
+ children: Iterable[Symbol] = current.children_recurse_anon
1047
+ else:
1048
+ children = current._children
876
1049
  for s in children:
877
1050
  if s.identOrOp == identOrOp:
878
1051
  return s
@@ -884,10 +1057,10 @@ class Symbol:
884
1057
  def direct_lookup(self, key: LookupKey) -> Symbol:
885
1058
  if Symbol.debug_lookup:
886
1059
  Symbol.debug_indent += 1
887
- Symbol.debug_print("direct_lookup:")
1060
+ Symbol.debug_print('direct_lookup:')
888
1061
  Symbol.debug_indent += 1
889
1062
  s = self
890
- for name, templateParams, id_ in key.data:
1063
+ for name, template_params, id_ in key.data:
891
1064
  if id_ is not None:
892
1065
  res = None
893
1066
  for cand in s._children:
@@ -898,22 +1071,25 @@ class Symbol:
898
1071
  break
899
1072
  s = res
900
1073
  else:
901
- identOrOp = name.identOrOp
902
- templateArgs = name.templateArgs
903
- s = s._find_first_named_symbol(identOrOp,
904
- templateParams, templateArgs,
905
- templateShorthand=False,
906
- matchSelf=False,
907
- recurseInAnon=False,
908
- correctPrimaryTemplateArgs=False)
1074
+ ident_or_op = name.identOrOp
1075
+ template_args = name.templateArgs
1076
+ s = s._find_first_named_symbol(
1077
+ ident_or_op,
1078
+ template_params,
1079
+ template_args,
1080
+ template_shorthand=False,
1081
+ match_self=False,
1082
+ recurse_in_anon=False,
1083
+ correct_primary_template_args=False,
1084
+ )
909
1085
  if Symbol.debug_lookup:
910
- Symbol.debug_print("name: ", name)
911
- Symbol.debug_print("templateParams:", templateParams)
912
- Symbol.debug_print("id: ", id_)
1086
+ Symbol.debug_print('name: ', name)
1087
+ Symbol.debug_print('template_params:', template_params)
1088
+ Symbol.debug_print('id: ', id_)
913
1089
  if s is not None:
914
- logger.debug(s.to_string(Symbol.debug_indent + 1), end="")
1090
+ logger.debug(s.to_string(Symbol.debug_indent + 1), end='')
915
1091
  else:
916
- Symbol.debug_print("not found")
1092
+ Symbol.debug_print('not found')
917
1093
  if s is None:
918
1094
  if Symbol.debug_lookup:
919
1095
  Symbol.debug_indent -= 2
@@ -937,68 +1113,78 @@ class Symbol:
937
1113
  # then the second component _may_ be a string explaining why.
938
1114
  if Symbol.debug_lookup:
939
1115
  Symbol.debug_indent += 1
940
- Symbol.debug_print("find_name:")
1116
+ Symbol.debug_print('find_name:')
941
1117
  Symbol.debug_indent += 1
942
- Symbol.debug_print("self:")
943
- logger.debug(self.to_string(Symbol.debug_indent + 1), end="")
944
- Symbol.debug_print("nestedName: ", nestedName)
945
- Symbol.debug_print("templateDecls: ", templateDecls)
946
- Symbol.debug_print("typ: ", typ)
947
- Symbol.debug_print("templateShorthand:", templateShorthand)
948
- Symbol.debug_print("matchSelf: ", matchSelf)
949
- Symbol.debug_print("recurseInAnon: ", recurseInAnon)
950
- Symbol.debug_print("searchInSiblings: ", searchInSiblings)
1118
+ Symbol.debug_print('self:')
1119
+ logger.debug(self.to_string(Symbol.debug_indent + 1), end='')
1120
+ Symbol.debug_print('nestedName: ', nestedName)
1121
+ Symbol.debug_print('templateDecls: ', templateDecls)
1122
+ Symbol.debug_print('typ: ', typ)
1123
+ Symbol.debug_print('templateShorthand:', templateShorthand)
1124
+ Symbol.debug_print('matchSelf: ', matchSelf)
1125
+ Symbol.debug_print('recurseInAnon: ', recurseInAnon)
1126
+ Symbol.debug_print('searchInSiblings: ', searchInSiblings)
951
1127
 
952
1128
  class QualifiedSymbolIsTemplateParam(Exception):
953
1129
  pass
954
1130
 
955
- def onMissingQualifiedSymbol(parentSymbol: Symbol,
956
- identOrOp: ASTIdentifier | ASTOperator,
957
- templateParams: Any,
958
- templateArgs: ASTTemplateArgs) -> Symbol | None:
1131
+ def on_missing_qualified_symbol(
1132
+ parent_symbol: Symbol,
1133
+ ident_or_op: ASTIdentifier | ASTOperator,
1134
+ template_params: Any,
1135
+ template_args: ASTTemplateArgs,
1136
+ ) -> Symbol | None:
959
1137
  # TODO: Maybe search without template args?
960
- # Though, the correctPrimaryTemplateArgs does
1138
+ # Though, the correct_primary_template_args does
961
1139
  # that for primary templates.
962
1140
  # Is there another case where it would be good?
963
- if parentSymbol.declaration is not None:
964
- if parentSymbol.declaration.objectType == 'templateParam':
1141
+ if parent_symbol.declaration is not None:
1142
+ if parent_symbol.declaration.objectType == 'templateParam':
965
1143
  raise QualifiedSymbolIsTemplateParam
966
1144
  return None
967
1145
 
968
1146
  try:
969
- lookupResult = self._symbol_lookup(nestedName, templateDecls,
970
- onMissingQualifiedSymbol,
971
- strictTemplateParamArgLists=False,
972
- ancestorLookupType=typ,
973
- templateShorthand=templateShorthand,
974
- matchSelf=matchSelf,
975
- recurseInAnon=recurseInAnon,
976
- correctPrimaryTemplateArgs=False,
977
- searchInSiblings=searchInSiblings)
1147
+ lookup_result = self._symbol_lookup(
1148
+ nestedName,
1149
+ templateDecls,
1150
+ on_missing_qualified_symbol,
1151
+ strict_template_param_arg_lists=False,
1152
+ ancestor_lookup_type=typ,
1153
+ template_shorthand=templateShorthand,
1154
+ match_self=matchSelf,
1155
+ recurse_in_anon=recurseInAnon,
1156
+ correct_primary_template_args=False,
1157
+ search_in_siblings=searchInSiblings,
1158
+ )
978
1159
  except QualifiedSymbolIsTemplateParam:
979
- return None, "templateParamInQualified"
1160
+ return None, 'templateParamInQualified'
980
1161
 
981
- if lookupResult is None:
1162
+ if lookup_result is None:
982
1163
  # if it was a part of the qualification that could not be found
983
1164
  if Symbol.debug_lookup:
984
1165
  Symbol.debug_indent -= 2
985
1166
  return None, None
986
1167
 
987
- res = list(lookupResult.symbols)
1168
+ res = list(lookup_result.symbols)
988
1169
  if len(res) != 0:
989
1170
  if Symbol.debug_lookup:
990
1171
  Symbol.debug_indent -= 2
991
1172
  return res, None
992
1173
 
993
- if lookupResult.parentSymbol.declaration is not None:
994
- if lookupResult.parentSymbol.declaration.objectType == 'templateParam':
995
- return None, "templateParamInQualified"
1174
+ if lookup_result.parent_symbol.declaration is not None:
1175
+ if lookup_result.parent_symbol.declaration.objectType == 'templateParam':
1176
+ return None, 'templateParamInQualified'
996
1177
 
997
1178
  # try without template params and args
998
- symbol = lookupResult.parentSymbol._find_first_named_symbol(
999
- lookupResult.identOrOp, None, None,
1000
- templateShorthand=templateShorthand, matchSelf=matchSelf,
1001
- recurseInAnon=recurseInAnon, correctPrimaryTemplateArgs=False)
1179
+ symbol = lookup_result.parent_symbol._find_first_named_symbol(
1180
+ lookup_result.ident_or_op,
1181
+ None,
1182
+ None,
1183
+ template_shorthand=templateShorthand,
1184
+ match_self=matchSelf,
1185
+ recurse_in_anon=recurseInAnon,
1186
+ correct_primary_template_args=False,
1187
+ )
1002
1188
  if Symbol.debug_lookup:
1003
1189
  Symbol.debug_indent -= 2
1004
1190
  if symbol is not None:
@@ -1006,58 +1192,71 @@ class Symbol:
1006
1192
  else:
1007
1193
  return None, None
1008
1194
 
1009
- def find_declaration(self, declaration: ASTDeclaration, typ: str, templateShorthand: bool,
1010
- matchSelf: bool, recurseInAnon: bool) -> Symbol | None:
1195
+ def find_declaration(
1196
+ self,
1197
+ declaration: ASTDeclaration,
1198
+ typ: str,
1199
+ templateShorthand: bool,
1200
+ matchSelf: bool,
1201
+ recurseInAnon: bool,
1202
+ ) -> Symbol | None:
1011
1203
  # templateShorthand: missing template parameter lists for templates is ok
1012
1204
  if Symbol.debug_lookup:
1013
1205
  Symbol.debug_indent += 1
1014
- Symbol.debug_print("find_declaration:")
1015
- nestedName = declaration.name
1206
+ Symbol.debug_print('find_declaration:')
1207
+ nested_name = declaration.name
1016
1208
  if declaration.templatePrefix:
1017
- templateDecls = declaration.templatePrefix.templates
1209
+ template_decls = declaration.templatePrefix.templates
1018
1210
  else:
1019
- templateDecls = []
1020
-
1021
- def onMissingQualifiedSymbol(parentSymbol: Symbol,
1022
- identOrOp: ASTIdentifier | ASTOperator,
1023
- templateParams: Any,
1024
- templateArgs: ASTTemplateArgs) -> Symbol | None:
1211
+ template_decls = []
1212
+
1213
+ def on_missing_qualified_symbol(
1214
+ parent_symbol: Symbol,
1215
+ ident_or_op: ASTIdentifier | ASTOperator,
1216
+ template_params: Any,
1217
+ template_args: ASTTemplateArgs,
1218
+ ) -> Symbol | None:
1025
1219
  return None
1026
1220
 
1027
- lookupResult = self._symbol_lookup(nestedName, templateDecls,
1028
- onMissingQualifiedSymbol,
1029
- strictTemplateParamArgLists=False,
1030
- ancestorLookupType=typ,
1031
- templateShorthand=templateShorthand,
1032
- matchSelf=matchSelf,
1033
- recurseInAnon=recurseInAnon,
1034
- correctPrimaryTemplateArgs=False,
1035
- searchInSiblings=False)
1221
+ lookup_result = self._symbol_lookup(
1222
+ nested_name,
1223
+ template_decls,
1224
+ on_missing_qualified_symbol,
1225
+ strict_template_param_arg_lists=False,
1226
+ ancestor_lookup_type=typ,
1227
+ template_shorthand=templateShorthand,
1228
+ match_self=matchSelf,
1229
+ recurse_in_anon=recurseInAnon,
1230
+ correct_primary_template_args=False,
1231
+ search_in_siblings=False,
1232
+ )
1036
1233
  if Symbol.debug_lookup:
1037
1234
  Symbol.debug_indent -= 1
1038
- if lookupResult is None:
1235
+ if lookup_result is None:
1039
1236
  return None
1040
1237
 
1041
- symbols = list(lookupResult.symbols)
1238
+ symbols = list(lookup_result.symbols)
1042
1239
  if len(symbols) == 0:
1043
1240
  return None
1044
1241
 
1045
- querySymbol = Symbol(parent=lookupResult.parentSymbol,
1046
- identOrOp=lookupResult.identOrOp,
1047
- templateParams=lookupResult.templateParams,
1048
- templateArgs=lookupResult.templateArgs,
1049
- declaration=declaration,
1050
- docname='fakeDocnameForQuery',
1051
- line=42)
1052
- queryId = declaration.get_newest_id()
1242
+ query_symbol = Symbol(
1243
+ parent=lookup_result.parent_symbol,
1244
+ identOrOp=lookup_result.ident_or_op,
1245
+ templateParams=lookup_result.template_params,
1246
+ templateArgs=lookup_result.template_args,
1247
+ declaration=declaration,
1248
+ docname='fakeDocnameForQuery',
1249
+ line=42,
1250
+ )
1251
+ query_id = declaration.get_newest_id()
1053
1252
  for symbol in symbols:
1054
1253
  if symbol.declaration is None:
1055
1254
  continue
1056
- candId = symbol.declaration.get_newest_id()
1057
- if candId == queryId:
1058
- querySymbol.remove()
1255
+ cand_id = symbol.declaration.get_newest_id()
1256
+ if cand_id == query_id:
1257
+ query_symbol.remove()
1059
1258
  return symbol
1060
- querySymbol.remove()
1259
+ query_symbol.remove()
1061
1260
  return None
1062
1261
 
1063
1262
  def to_string(self, indent: int) -> str:
@@ -1066,9 +1265,11 @@ class Symbol:
1066
1265
  res.append('::')
1067
1266
  else:
1068
1267
  if self.templateParams:
1069
- res.append(str(self.templateParams))
1070
- res.append('\n')
1071
- res.append(Symbol.debug_indent_string * indent)
1268
+ res.extend((
1269
+ str(self.templateParams),
1270
+ '\n',
1271
+ Symbol.debug_indent_string * indent,
1272
+ ))
1072
1273
  if self.identOrOp:
1073
1274
  res.append(str(self.identOrOp))
1074
1275
  else:
@@ -1076,15 +1277,17 @@ class Symbol:
1076
1277
  if self.templateArgs:
1077
1278
  res.append(str(self.templateArgs))
1078
1279
  if self.declaration:
1079
- res.append(": ")
1280
+ res.append(': ')
1080
1281
  if self.isRedeclaration:
1081
1282
  res.append('!!duplicate!! ')
1082
- res.append("{" + self.declaration.objectType + "} ")
1083
- res.append(str(self.declaration))
1283
+ res.extend((
1284
+ '{',
1285
+ self.declaration.objectType,
1286
+ '} ',
1287
+ str(self.declaration),
1288
+ ))
1084
1289
  if self.docname:
1085
- res.append('\t(')
1086
- res.append(self.docname)
1087
- res.append(')')
1290
+ res.extend(('\t(', self.docname, ')'))
1088
1291
  res.append('\n')
1089
1292
  return ''.join(res)
1090
1293