Skip to content

Commit 6fac4d0

Browse files
authored
🐛 FIX RemovedInSphinx10Warning for inventory item iteration (#1129)
Fixes the deprecation warning from Sphinx >= 8.2: ``` RemovedInSphinx10Warning: The iter() interface for _InventoryItem objects is deprecated. Please access the `project_name`, `project_version`, `uri`, and `displayname` attributes directly. ``` The previous code unpacked `_InventoryItem` as a tuple (`project, version, loc, text = data[target]`), which triggers the warning. This uses `hasattr` to detect whether the new attribute-based API is available and falls back to tuple unpacking for older Sphinx versions. This approach is more robust than version checking (cf. #1079 which used `sphinx.__version_info__` — an attribute that doesn't exist; the correct attribute is `sphinx.version_info`). Note: the correct attribute name on `_InventoryItem` is `display_name` (with underscore), despite the warning message saying `displayname`.
1 parent 9364edb commit 6fac4d0

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

docs/conf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,9 @@
197197
tippy_skip_anchor_classes = ("headerlink", "sd-stretched-link", "sd-rounded-pill")
198198
tippy_anchor_parent_selector = "article.bd-article"
199199
tippy_rtd_urls = [
200-
"https://www.sphinx-doc.org/en/master",
201-
"https://markdown-it-py.readthedocs.io/en/latest",
200+
# TODO these are failing the build: Expecting value: line 1 column 1 (char 0)
201+
# "https://www.sphinx-doc.org/en/master",
202+
# "https://markdown-it-py.readthedocs.io/en/latest",
202203
]
203204
# TODO failing
204205
tippy_enable_wikitips = False

docs/syntax/cross-referencing.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ Sphinx offers numerous [roles for referencing](#usage/restructuredtext/roles) sp
379379
These can also be used within MyST documents, although it is recommended to use the Markdown syntax where possible, which is more portable and native to MyST.
380380

381381
:::{myst-example}
382+
Sphinx roles:
383+
382384
- {ref}`syntax/referencing`, {ref}`Explicit text <syntax/referencing>`
383385
- {term}`my other term`
384386
- {doc}`../intro`, {doc}`Explicit text <../intro>`
@@ -387,7 +389,7 @@ These can also be used within MyST documents, although it is recommended to use
387389
- {external:class}`sphinx.application.Sphinx`, {external:class}`Explicit text <sphinx.application.Sphinx>`
388390
- {external+sphinx:ref}`code-examples`, {external+sphinx:ref}`Explicit text <code-examples>`
389391

390-
---
392+
MyST native:
391393

392394
- <project:#syntax/referencing>, [][syntax], [Explicit text][syntax]
393395
- [](<#my other term>)

docs/syntax/organising_content.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ All headings at the root level of the document are included in the Table of Cont
1515

1616
Many HTML themes will already include this ToC in a sidebar, but you can also include it in the main content of the page using the contents {{directive}}:
1717

18-
:::{myst-example}
18+
````myst
19+
```{contents} Table of Contents
20+
:depth: 3
21+
```
22+
````
23+
1924
```{contents} Table of Contents
2025
:depth: 3
2126
```
22-
:::
2327

2428
Options:
2529

myst_parser/inventory.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,15 @@ def filter_sphinx_inventories(
366366
continue
367367
for target in data:
368368
if match_with_wildcard(target, targets):
369-
project, version, loc, text = data[target]
369+
data_target = data[target]
370+
if hasattr(data_target, "project_name"):
371+
# Sphinx >= 8.2
372+
project = data_target.project_name
373+
version = data_target.project_version
374+
loc = data_target.uri
375+
text = data_target.display_name
376+
else:
377+
project, version, loc, text = data_target
370378
yield (
371379
InvMatch(
372380
inv=inv_name,

0 commit comments

Comments
 (0)