Migrate to py3 style type annotation: sphinx.ext.imgconverter

This commit is contained in:
Takeshi KOMIYA 2019-06-15 23:30:04 +09:00
parent 462902aea6
commit 30ddf70742

View File

@ -7,19 +7,17 @@
:copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS. :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
import subprocess import subprocess
from subprocess import CalledProcessError, PIPE from subprocess import CalledProcessError, PIPE
from typing import Any, Dict
from sphinx.application import Sphinx
from sphinx.errors import ExtensionError from sphinx.errors import ExtensionError
from sphinx.locale import __ from sphinx.locale import __
from sphinx.transforms.post_transforms.images import ImageConverter from sphinx.transforms.post_transforms.images import ImageConverter
from sphinx.util import logging from sphinx.util import logging
if False:
# For type annotation
from typing import Any, Dict # NOQA
from sphinx.application import Sphinx # NOQA
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -31,8 +29,7 @@ class ImagemagickConverter(ImageConverter):
('application/pdf', 'image/png'), ('application/pdf', 'image/png'),
] ]
def is_available(self): def is_available(self) -> bool:
# type: () -> bool
"""Confirms the converter is available or not.""" """Confirms the converter is available or not."""
try: try:
args = [self.config.image_converter, '-version'] args = [self.config.image_converter, '-version']
@ -50,8 +47,7 @@ class ImagemagickConverter(ImageConverter):
exc.stderr, exc.stdout) exc.stderr, exc.stdout)
return False return False
def convert(self, _from, _to): def convert(self, _from: str, _to: str) -> bool:
# type: (str, str) -> bool
"""Converts the image to expected one.""" """Converts the image to expected one."""
try: try:
# append an index 0 to source filename to pick up the first frame # append an index 0 to source filename to pick up the first frame
@ -75,8 +71,7 @@ class ImagemagickConverter(ImageConverter):
(exc.stderr, exc.stdout)) (exc.stderr, exc.stdout))
def setup(app): def setup(app: Sphinx) -> Dict[str, Any]:
# type: (Sphinx) -> Dict[str, Any]
app.add_post_transform(ImagemagickConverter) app.add_post_transform(ImagemagickConverter)
app.add_config_value('image_converter', 'convert', 'env') app.add_config_value('image_converter', 'convert', 'env')
app.add_config_value('image_converter_args', [], 'env') app.add_config_value('image_converter_args', [], 'env')