Skip to content

Commit 296ad89

Browse files
committed
🐛 FIX: Fix RemovedInSphinx10Warning for inventory item iteration
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 bb34147 commit 296ad89

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

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)