diff --git a/sphinxcontrib/qthelp/__init__.py b/sphinxcontrib/qthelp/__init__.py index a84b788..bdd32e5 100644 --- a/sphinxcontrib/qthelp/__init__.py +++ b/sphinxcontrib/qthelp/__init__.py @@ -8,13 +8,15 @@ :license: BSD, see LICENSE for details. """ +from __future__ import annotations + import html import os import posixpath import re from os import path from pathlib import Path -from typing import Any, Dict, Iterable, List, Tuple, cast +from typing import TYPE_CHECKING, Any, cast from docutils import nodes from docutils.nodes import Node @@ -28,6 +30,9 @@ from sphinx.util.osutil import canon_path, make_filename from sphinx.util.template import SphinxRenderer +if TYPE_CHECKING: + from collections.abc import Iterable + __version__ = '1.0.4' __version_info__ = (1, 0, 4) @@ -83,7 +88,7 @@ def init(self) -> None: self.link_suffix = '.html' # self.config.html_style = 'traditional.css' - def get_theme_config(self) -> Tuple[str, Dict]: + def get_theme_config(self) -> tuple[str, dict]: return self.config.qthelp_theme, self.config.qthelp_theme_options def handle_finish(self) -> None: @@ -165,8 +170,8 @@ def isdocnode(self, node: Node) -> bool: return False return True - def write_toc(self, node: Node, indentlevel: int = 4) -> List[str]: - parts = [] # type: List[str] + def write_toc(self, node: Node, indentlevel: int = 4) -> list[str]: + parts: list[str] = [] if isinstance(node, nodes.list_item) and self.isdocnode(node): compact_paragraph = cast(addnodes.compact_paragraph, node[0]) reference = cast(nodes.reference, compact_paragraph[0]) @@ -221,8 +226,8 @@ def keyword_item(self, name: str, ref: Any) -> str: item.encode('ascii', 'xmlcharrefreplace') return item - def build_keywords(self, title: str, refs: List[Any], subitems: Any) -> List[str]: - keywords = [] # type: List[str] + def build_keywords(self, title: str, refs: list[Any], subitems: Any) -> list[str]: + keywords: list[str] = [] # if len(refs) == 0: # XXX # write_param('See Also', title) @@ -243,7 +248,7 @@ def build_keywords(self, title: str, refs: List[Any], subitems: Any) -> List[str return keywords - def get_project_files(self, outdir: Path) -> List[str]: + def get_project_files(self, outdir: Path) -> list[str]: project_files = [] staticdir = path.join(outdir, '_static') imagesdir = path.join(outdir, self.imagedir) @@ -257,7 +262,7 @@ def get_project_files(self, outdir: Path) -> List[str]: return project_files -def setup(app: Sphinx) -> Dict[str, Any]: +def setup(app: Sphinx) -> dict[str, Any]: app.setup_extension('sphinx.builders.html') app.add_builder(QtHelpBuilder) app.add_message_catalog(__name__, path.join(package_dir, 'locales'))