Skip to content

Commit 9b27ad8

Browse files
committed
Add static types for the HTML context dict
1 parent bfecf2c commit 9b27ad8

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

sphinx/builders/html/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
from docutils.nodes import Node
7171

7272
from sphinx.application import Sphinx
73-
from sphinx.builders.html._ctx import _GlobalContextHTML, _PageContext
73+
from sphinx.builders.html._ctx import _GlobalContextHTML, _PageContextHTML
7474
from sphinx.config import Config
7575
from sphinx.environment import BuildEnvironment
7676
from sphinx.util.typing import ExtensionMetadata
@@ -1043,7 +1043,7 @@ def get_output_path(self, page_name: str, /) -> Path:
10431043
def get_outfilename(self, pagename: str) -> _StrPath:
10441044
return _StrPath(self.get_output_path(pagename))
10451045

1046-
def add_sidebars(self, pagename: str, ctx: _PageContext) -> None:
1046+
def add_sidebars(self, pagename: str, ctx: _PageContextHTML) -> None:
10471047
def has_wildcard(pattern: str) -> bool:
10481048
return any(char in pattern for char in '*?[')
10491049

@@ -1083,7 +1083,7 @@ def handle_page(
10831083
outfilename: Path | None = None,
10841084
event_arg: Any = None,
10851085
) -> None:
1086-
ctx: _PageContext = self.globalcontext.copy() # type: ignore[assignment]
1086+
ctx: _PageContextHTML = self.globalcontext.copy() # type: ignore[assignment]
10871087
# current_page_name is backwards compatibility
10881088
ctx['pagename'] = ctx['current_page_name'] = pagename
10891089
ctx['encoding'] = self.config.html_output_encoding
@@ -1264,7 +1264,7 @@ def js_tag(js: _JavaScript | str) -> str:
12641264
copyfile(self.env.doc2path(pagename), source_file_path, force=True)
12651265

12661266
def update_page_context(
1267-
self, pagename: str, templatename: str, ctx: _PageContext, event_arg: Any
1267+
self, pagename: str, templatename: str, ctx: _PageContextHTML, event_arg: Any
12681268
) -> None:
12691269
pass
12701270

sphinx/builders/html/_ctx.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __call__(
5555
class _ToctreeCallable(Protocol):
5656
def __call__(self, **kwargs: Any) -> str: ...
5757

58-
class _PageContext(_GlobalContextHTML):
58+
class _PageContextHTML(_GlobalContextHTML):
5959
# get_doc_context()
6060
prev: Sequence[_NavigationRelation]
6161
next: Sequence[_NavigationRelation]
@@ -84,4 +84,6 @@ class _PageContext(_GlobalContextHTML):
8484
sidebars: Sequence[str] | None
8585

8686
else:
87+
_NavigationRelation = dict
8788
_GlobalContextHTML = dict
89+
_PageContextHTML = dict

tests/test_builders/test_build_html.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from tests.test_builders.xpath_util import check_xpath
3131

3232
if TYPE_CHECKING:
33-
from sphinx.builders.html._ctx import _PageContext
33+
from sphinx.builders.html._ctx import _PageContextHTML
3434
from sphinx.testing.util import SphinxTestApp
3535

3636

@@ -415,7 +415,7 @@ def test_html_style(app: SphinxTestApp) -> None:
415415
},
416416
)
417417
def test_html_sidebar(app: SphinxTestApp) -> None:
418-
ctx: _PageContext = {} # type: ignore[typeddict-item]
418+
ctx: _PageContextHTML = {} # type: ignore[typeddict-item]
419419

420420
# default for alabaster
421421
app.build(force_all=True)

0 commit comments

Comments
 (0)