Skip to content

Commit 3e4cba8

Browse files
authored
Fix tests for Sphinx 8.2 (#200)
* Fix tests * remove fixed type hint
1 parent beac435 commit 3e4cba8

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/scanpydoc/release_notes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def render_include(self, path: Path) -> Sequence[nodes.Node]:
143143
d = MockIncludeDirective(
144144
renderer=self._myst_renderer,
145145
name=type(self).__name__,
146-
klass=Include, # type: ignore[arg-type] # wrong type hint
146+
klass=Include,
147147
arguments=[str(path.relative_to(parent_dir))],
148148
options={},
149149
body=[],

tests/test_elegant_typehints.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,26 @@
55
import re
66
import inspect
77
from io import StringIO
8-
from typing import TYPE_CHECKING, Any, AnyStr, NoReturn, cast, get_origin
8+
from typing import TYPE_CHECKING, Any, AnyStr, NoReturn, NamedTuple, cast, get_origin
99
from pathlib import Path
1010
from operator import attrgetter
1111
from collections.abc import Mapping, Callable
12+
from importlib.metadata import version
1213

1314
import pytest
15+
from packaging.version import Version
16+
17+
18+
if TYPE_CHECKING or Version(version("sphinx")) >= Version("8.2"):
19+
from sphinx.util.inventory import _InventoryItem
20+
else:
21+
22+
class _InventoryItem(NamedTuple):
23+
project_name: str
24+
project_version: str
25+
uri: str
26+
display_name: str
27+
1428

1529
from scanpydoc.elegant_typehints import _last_resolve, qualname_overrides
1630
from scanpydoc.elegant_typehints._formatting import typehints_formatter
@@ -262,7 +276,12 @@ def test_resolve(app: Sphinx, qualname: str, docname: str) -> None:
262276

263277
# Inventory contains documented name
264278
InventoryAdapter(app.env).main_inventory["py:class"] = {
265-
docname: ("TestProj", "1", "https://x.com", docname.split(".")[-1]),
279+
docname: _InventoryItem(
280+
project_name="TestProj",
281+
project_version="1",
282+
uri="https://x.com",
283+
display_name=docname.split(".")[-1],
284+
),
266285
}
267286
# Node contains name from code
268287
node = pending_xref(refdomain="py", reftarget=qualname, reftype="class")

0 commit comments

Comments
 (0)