2121from sphinx .errors import SphinxError
2222from sphinx .util .osutil import ensuredir , relative_uri
2323
24+ if t .TYPE_CHECKING :
25+ from sphinx .application import Sphinx
26+
27+
2428try :
2529 import aafigure
2630except ImportError :
3236DEFAULT_FORMATS = {"html" : "svg" , "latex" : "pdf" , "text" : None }
3337
3438
35- def merge_dict (dst , src ):
39+ def merge_dict (
40+ dst : t .Dict [str , t .Optional [str ]], src : t .Dict [str , t .Optional [str ]]
41+ ) -> t .Dict [str , t .Optional [str ]]:
3642 for k , v in src .items ():
3743 if k not in dst :
3844 dst [k ] = v
3945 return dst
4046
4147
42- def get_basename (text , options , prefix = "aafig" ):
48+ def get_basename (
49+ text : str , options : t .Dict [str , str ], prefix : t .Optional [str ] = "aafig"
50+ ) -> str :
4351 options = options .copy ()
4452 if "format" in options :
4553 del options ["format" ]
@@ -52,7 +60,7 @@ class AafigError(SphinxError):
5260 category = "aafig error"
5361
5462
55- class AafigDirective (images .Image ):
63+ class AafigDirective (images .Image ): # type:ignore
5664 """
5765 Directive to insert an ASCII art figure to be rendered by aafigure.
5866 """
@@ -71,7 +79,7 @@ class AafigDirective(images.Image):
7179 option_spec = images .Image .option_spec .copy ()
7280 option_spec .update (own_option_spec )
7381
74- def run (self ):
82+ def run (self ) -> t . List [ nodes . Node ] :
7583 aafig_options = {}
7684 own_options_keys = [self .own_option_spec .keys (), "scale" ]
7785 for k , v in self .options .items ():
@@ -93,7 +101,7 @@ def run(self):
93101 return [image_node ]
94102
95103
96- def render_aafig_images (app , doctree ) :
104+ def render_aafig_images (app : "Sphinx" , doctree : nodes . Node ) -> None :
97105 format_map = app .builder .config .aafig_format
98106 merge_dict (format_map , DEFAULT_FORMATS )
99107 if aafigure is None :
@@ -144,7 +152,9 @@ def __init__(self, *args: object, **kwargs: object) -> None:
144152 return super ().__init__ ("aafigure module not installed" , * args , ** kwargs )
145153
146154
147- def render_aafigure (app , text , options ):
155+ def render_aafigure (
156+ app : "Sphinx" , text : str , options : t .Dict [str , str ]
157+ ) -> t .Tuple [str , str , t .Optional [str ], t .Optional [str ]]:
148158 """
149159 Render an ASCII art figure into the requested format output file.
150160 """
@@ -186,7 +196,7 @@ def render_aafigure(app, text, options):
186196 finally :
187197 if f is not None :
188198 f .close ()
189- return relfn , outfn , id , extra
199+ return relfn , outfn , None , extra
190200 except AafigError :
191201 pass
192202
@@ -204,10 +214,10 @@ def render_aafigure(app, text, options):
204214 with open (metadata_fname , "w" ) as f :
205215 f .write (extra )
206216
207- return relfn , outfn , id , extra
217+ return relfn , outfn , None , extra
208218
209219
210- def setup (app ) :
220+ def setup (app : "Sphinx" ) -> None :
211221 app .add_directive ("aafig" , AafigDirective )
212222 app .connect ("doctree-read" , render_aafig_images )
213223 app .add_config_value ("aafig_format" , DEFAULT_FORMATS , "html" )
0 commit comments