From 2ba38dd2a18ab57ed7aac7ccdd6a42ff5e4d4eb7 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Fri, 12 Oct 2018 11:58:01 +0200 Subject: Bump mypy typing coverage --- libmat2/images.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'libmat2/images.py') diff --git a/libmat2/images.py b/libmat2/images.py index 8f7a98d..a29cbb7 100644 --- a/libmat2/images.py +++ b/libmat2/images.py @@ -5,7 +5,7 @@ import os import shutil import tempfile import re -from typing import Set +from typing import Set, Dict, Union import cairo @@ -25,7 +25,7 @@ class _ImageParser(abstract.AbstractParser): meta_whitelist = set() # type: Set[str] @staticmethod - def __handle_problematic_filename(filename: str, callback) -> str: + def __handle_problematic_filename(filename: str, callback) -> bytes: """ This method takes a filename with a problematic name, and safely applies it a `callback`.""" tmpdirname = tempfile.mkdtemp() @@ -35,7 +35,7 @@ class _ImageParser(abstract.AbstractParser): shutil.rmtree(tmpdirname) return out - def get_meta(self): + def get_meta(self) -> Dict[str, Union[str, dict]]: """ There is no way to escape the leading(s) dash(es) of the current self.filename to prevent parameter injections, so we need to take care of this. @@ -71,7 +71,7 @@ class PNGParser(_ImageParser): except MemoryError: # pragma: no cover raise ValueError - def remove_all(self): + def remove_all(self) -> bool: surface = cairo.ImageSurface.create_from_png(self.filename) surface.write_to_png(self.output_filename) return True @@ -83,7 +83,12 @@ class GdkPixbufAbstractParser(_ImageParser): """ _type = '' - def remove_all(self): + def __init__(self, filename): + super().__init__(filename) + if imghdr.what(filename) != self._type: # better safe than sorry + raise ValueError + + def remove_all(self) -> bool: _, extension = os.path.splitext(self.filename) pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.filename) if extension.lower() == '.jpg': @@ -91,11 +96,6 @@ class GdkPixbufAbstractParser(_ImageParser): pixbuf.savev(self.output_filename, extension[1:], [], []) return True - def __init__(self, filename): - super().__init__(filename) - if imghdr.what(filename) != self._type: # better safe than sorry - raise ValueError - class JPGParser(GdkPixbufAbstractParser): _type = 'jpeg' -- cgit v1.3