Skip to content

Commit

Permalink
Fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Aug 16, 2024
1 parent cea0e97 commit dff8aa7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
6 changes: 5 additions & 1 deletion sphinx/domains/_domains_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
...
Expand All @@ -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:
...
Expand Down
12 changes: 5 additions & 7 deletions sphinx/ext/autosummary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,21 @@ 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] = {}
self.srcdir = 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)
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions sphinx/testing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def __init__(
# unknown keyword arguments
**extras: Any,
) -> None:
self._buildername = buildername
self._builder_name = buildername

assert srcdir is not None

Expand Down Expand Up @@ -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()
Expand Down
22 changes: 13 additions & 9 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import warnings
from io import BytesIO
from typing import TYPE_CHECKING

import pytest
from docutils import frontend, utils
Expand All @@ -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()
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit dff8aa7

Please sign in to comment.