diff --git a/sphinx/domains/_domains_container.py b/sphinx/domains/_domains_container.py index c109e1a41c9..3166753c321 100644 --- a/sphinx/domains/_domains_container.py +++ b/sphinx/domains/_domains_container.py @@ -199,7 +199,7 @@ def __delattr__(self, key: str) -> None: raise TypeError(msg) super().__delattr__(key) - # Mapping interface + # Mapping interface: builtin domains @overload def __getitem__(self, key: Literal["c"]) -> CDomain: @@ -241,6 +241,8 @@ def __getitem__(self, key: Literal["rst"]) -> ReSTDomain: def __getitem__(self, key: Literal["std"]) -> StandardDomain: ... + # Mapping interface: first-party domains + @overload def __getitem__(self, key: Literal["duration"]) -> DurationDomain: ... @@ -249,6 +251,8 @@ def __getitem__(self, key: Literal["duration"]) -> DurationDomain: def __getitem__(self, key: Literal["todo"]) -> TodoDomain: ... + # Mapping interface: third-party domains + @overload def __getitem__(self, key: str) -> Domain: ... diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index 5a6a741f78c..01a79563f38 100644 --- a/sphinx/ext/autosummary/__init__.py +++ b/sphinx/ext/autosummary/__init__.py @@ -152,7 +152,7 @@ def autosummary_table_visit_html(self: HTML5Translator, node: autosummary_table) # -- autodoc integration ------------------------------------------------------- class FakeApplication: - def __init__(self, *, registry: SphinxComponentRegistry) -> None: + def __init__(self) -> None: self.doctreedir = None self.events = None self.extensions: dict[str, Extension] = {} @@ -160,14 +160,13 @@ def __init__(self, *, registry: SphinxComponentRegistry) -> None: self.config = Config() self.project = Project('', {}) self.registry = SphinxComponentRegistry() - # self.registry.domains |= registry.domains class FakeDirective(DocumenterBridge): - def __init__(self, *, registry: SphinxComponentRegistry) -> None: + def __init__(self) -> None: settings = Struct(tab_width=8) document = Struct(settings=settings) - app = FakeApplication(registry=registry) + app = FakeApplication() app.config.add('autodoc_class_signature', 'mixed', 'env', ()) env = BuildEnvironment(app) # type: ignore[arg-type] state = Struct(document=document) @@ -194,11 +193,10 @@ def get_documenter(app: Sphinx, obj: Any, parent: Any) -> type[Documenter]: else: parent_doc_cls = ModuleDocumenter - bridge = FakeDirective(registry=app.registry) if hasattr(parent, '__name__'): - parent_doc = parent_doc_cls(bridge, parent.__name__) + parent_doc = parent_doc_cls(FakeDirective(), parent.__name__) else: - parent_doc = parent_doc_cls(bridge, "") + parent_doc = parent_doc_cls(FakeDirective(), "") # Get the correct documenter class for *obj* classes = [cls for cls in app.registry.documenters.values() diff --git a/sphinx/testing/util.py b/sphinx/testing/util.py index 58608dcdc7d..f99442eb004 100644 --- a/sphinx/testing/util.py +++ b/sphinx/testing/util.py @@ -123,7 +123,7 @@ def __init__( # unknown keyword arguments **extras: Any, ) -> None: - self._buildername = buildername + self._builder_name = buildername assert srcdir is not None @@ -211,7 +211,7 @@ def cleanup(self, doctrees: bool = False) -> None: os.remove(self.docutils_conf_path) def __repr__(self) -> str: - return f'<{self.__class__.__name__} buildername={self._buildername!r}>' + return f'<{self.__class__.__name__} buildername={self._builder_name!r}>' def build(self, force_all: bool = False, filenames: list[str] | None = None) -> None: self.env._pickled_doctree_cache.clear() diff --git a/tests/test_search.py b/tests/test_search.py index dfbda5d4726..a0c4cc0859f 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -5,6 +5,7 @@ import json import warnings from io import BytesIO +from typing import TYPE_CHECKING import pytest from docutils import frontend, utils @@ -14,6 +15,9 @@ from tests.utils import TESTS_ROOT +if TYPE_CHECKING: + from collections.abc import Iterator + JAVASCRIPT_TEST_ROOTS = [ directory for directory in (TESTS_ROOT / 'js' / 'roots').iterdir() @@ -22,30 +26,30 @@ class DummyDomainsContainer: - def __init__(self, domains): + def __init__(self, **domains: DummyDomain) -> None: self._domain_instances = domains - def sorted_domains(self): + def sorted_domains(self) -> Iterator[DummyDomain]: for _domain_name, domain in sorted(self._domain_instances.items()): yield domain class DummyEnvironment: - def __init__(self, version, domains): + def __init__(self, version: str, domains: DummyDomainsContainer) -> None: self.version = version - self.domains = DummyDomainsContainer(domains) + self.domains = domains - def __getattr__(self, name): + def __getattr__(self, name: str): if name.startswith('_search_index_'): setattr(self, name, {}) return getattr(self, name, {}) - def __str__(self): + def __str__(self) -> str: return f'DummyEnvironment({self.version!r}, {self.domains!r})' class DummyDomain: - def __init__(self, name, data): + def __init__(self, name: str, data: dict) -> None: self.name = name self.data = data self.object_types = {} @@ -186,7 +190,7 @@ def test_IndexBuilder(): ('objname2', 'objdispname2', 'objtype2', 'docname2_2', '', -1), ], ) - env = DummyEnvironment('1.0', {'dummy1': domain1, 'dummy2': domain2}) + env = DummyEnvironment('1.0', DummyDomainsContainer(dummy1=domain1, dummy2=domain2)) doc = utils.new_document(b'test data', settings) doc['file'] = 'dummy' parser.parse(FILE_CONTENTS, doc) @@ -274,7 +278,7 @@ def test_IndexBuilder(): 1: ('dummy2', 'objtype1', 'objtype1'), } - env = DummyEnvironment('1.0', {'dummy1': domain1, 'dummy2': domain2}) + env = DummyEnvironment('1.0', DummyDomainsContainer(dummy1=domain1, dummy2=domain2)) # dump / load stream = BytesIO()