Skip to content

Commit ae8b377

Browse files
Improve typing for mocksvgconverter.py (#12788)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
1 parent d1c23a0 commit ae8b377

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

tests/roots/test-ext-imgmockconverter/mocksvgconverter.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,33 @@
22
Does foo.svg --> foo.pdf with no change to the file.
33
"""
44

5+
from __future__ import annotations
6+
57
import shutil
8+
from typing import TYPE_CHECKING
69

710
from sphinx.transforms.post_transforms.images import ImageConverter
811

9-
if False:
10-
# For type annotation
11-
from typing import Any, Dict # NoQA
12+
if TYPE_CHECKING:
13+
from sphinx.application import Sphinx
14+
from sphinx.util.typing import ExtensionMetadata
1215

13-
from sphinx.application import Sphinx # NoQA
1416

1517
class MyConverter(ImageConverter):
1618
conversion_rules = [
1719
('image/svg+xml', 'application/pdf'),
1820
]
1921

20-
def is_available(self):
21-
# type: () -> bool
22+
def is_available(self) -> bool:
2223
return True
2324

24-
def convert(self, _from, _to):
25-
# type: (unicode, unicode) -> bool
25+
def convert(self, _from: str, _to: str) -> bool:
2626
"""Mock converts the image from SVG to PDF."""
2727
shutil.copyfile(_from, _to)
2828
return True
2929

3030

31-
def setup(app):
32-
# type: (Sphinx) -> Dict[unicode, Any]
31+
def setup(app: Sphinx) -> ExtensionMetadata:
3332
app.add_post_transform(MyConverter)
3433

3534
return {

0 commit comments

Comments
 (0)