99import os
1010import re
1111from os import path
12- from typing import Any
12+ from typing import TYPE_CHECKING , Any
1313
1414from docutils import nodes
1515from sphinx import addnodes
16- from sphinx .application import Sphinx
1716from sphinx .builders .html import StandaloneHTMLBuilder
1817from sphinx .environment .adapters .indexentries import IndexEntries
1918from sphinx .locale import get_translation
2019from sphinx .util import logging
2120from sphinx .util .nodes import NodeMatcher
2221from sphinx .util .osutil import make_filename
2322
24- try :
25- import xml . etree . ElementTree as etree
26- except ImportError :
27- import lxml .etree as etree # type: ignore
23+ if TYPE_CHECKING :
24+ from sphinx . application import Sphinx
25+
26+ import xml .etree . ElementTree as etree
2827
2928__version__ = '1.0.6'
3029__version_info__ = (1 , 0 , 6 )
@@ -80,8 +79,7 @@ def build_devhelp(self, outdir: str | os.PathLike[str], outname: str) -> None:
8079 self .config .master_doc , self , prune_toctrees = False )
8180
8281 def write_toc (node : nodes .Node , parent : etree .Element ) -> None :
83- if isinstance (node , addnodes .compact_paragraph ) or \
84- isinstance (node , nodes .bullet_list ):
82+ if isinstance (node , (addnodes .compact_paragraph , nodes .bullet_list )):
8583 for subnode in node :
8684 write_toc (subnode , parent )
8785 elif isinstance (node , nodes .list_item ):
@@ -93,7 +91,7 @@ def write_toc(node: nodes.Node, parent: etree.Element) -> None:
9391 parent .attrib ['name' ] = node .astext ()
9492
9593 matcher = NodeMatcher (addnodes .compact_paragraph , toctree = Any )
96- for node in tocdoc .findall (matcher ): # type: addnodes.compact_paragraph
94+ for node in tocdoc .findall (matcher ):
9795 write_toc (node , chapters )
9896
9997 # Index
@@ -115,7 +113,7 @@ def write_index(title: str, refs: list[Any], subitems: Any) -> None:
115113 if subitems :
116114 parent_title = re .sub (r'\s*\(.*\)\s*$' , '' , title )
117115 for subitem in subitems :
118- write_index ("%s %s" % ( parent_title , subitem [0 ]) ,
116+ write_index (f' { parent_title } { subitem [0 ]} ' ,
119117 subitem [1 ], [])
120118
121119 for (_group_key , group ) in index :
@@ -125,7 +123,7 @@ def write_index(title: str, refs: list[Any], subitems: Any) -> None:
125123 # Dump the XML file
126124 xmlfile = path .join (outdir , outname + '.devhelp.gz' )
127125 with gzip .GzipFile (filename = xmlfile , mode = 'w' , mtime = 0 ) as f :
128- tree .write (f , 'utf-8' ) # type: ignore
126+ tree .write (f , 'utf-8' )
129127
130128
131129def setup (app : Sphinx ) -> dict [str , Any ]:
0 commit comments