Skip to content

Commit c527a81

Browse files
Add type hints
1 parent e670cdf commit c527a81

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

python_docs_theme/__init__.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
TYPE_CHECKING = False
88
if TYPE_CHECKING:
9+
from typing import Any
10+
911
from sphinx.application import Sphinx
1012
from sphinx.util.typing import ExtensionMetadata
1113

@@ -16,15 +18,21 @@
1618
MESSAGE_CATALOG_NAME = "python-docs-theme"
1719

1820

19-
def add_translation_to_context(app, pagename, templatename, context, doctree):
21+
def add_translation_to_context(
22+
app: Sphinx,
23+
pagename: str,
24+
templatename: str,
25+
context: dict[str, Any],
26+
doctree: None,
27+
) -> None:
2028
theme_gettext = get_translation(MESSAGE_CATALOG_NAME)
2129
sphinx_gettext = get_translation("sphinx")
2230

23-
def combined(msg):
24-
trans = theme_gettext(msg)
25-
if trans == msg:
26-
return sphinx_gettext(msg)
27-
return trans
31+
def combined(message: str) -> str:
32+
translation = theme_gettext(message)
33+
if translation == message:
34+
return sphinx_gettext(message)
35+
return translation
2836

2937
context["_"] = context["gettext"] = context["ngettext"] = combined
3038

0 commit comments

Comments
 (0)