Skip to content

Commit 883bb28

Browse files
committed
chore(mypy): Add typings for aafig
1 parent fedc315 commit 883bb28

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

docs/_ext/aafig.py

+19-9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
from sphinx.errors import SphinxError
2222
from sphinx.util.osutil import ensuredir, relative_uri
2323

24+
if t.TYPE_CHECKING:
25+
from sphinx.application import Sphinx
26+
27+
2428
try:
2529
import aafigure
2630
except ImportError:
@@ -32,14 +36,18 @@
3236
DEFAULT_FORMATS = {"html": "svg", "latex": "pdf", "text": None}
3337

3438

35-
def merge_dict(dst, src):
39+
def merge_dict(
40+
dst: dict[str, str | None], src: dict[str, str | None]
41+
) -> dict[str, str | None]:
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: dict[str, str], prefix: str | None = "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) -> 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: dict[str, str]
157+
) -> tuple[str, str, str | None, str | None]:
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

Comments
 (0)