From 2fa37aa22b46946719479fe8f0f7d80a76d4f0d1 Mon Sep 17 00:00:00 2001 From: wisp3rwind <17089248+wisp3rwind@users.noreply.github.com> Date: Sat, 12 Feb 2022 22:59:52 +0100 Subject: [PATCH] artresizer: return None explicitly `None` is used both as a marker when errors occured, and when a function is not implemented by the backend. That is already confusing enough without there being implicit `None` return values when falling of the tail of a method --- beets/util/artresizer.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/beets/util/artresizer.py b/beets/util/artresizer.py index 0260c6f82..d1a544bd8 100644 --- a/beets/util/artresizer.py +++ b/beets/util/artresizer.py @@ -177,6 +177,7 @@ def pil_getsize(artresizer, path_in): except OSError as exc: log.error("PIL could not read file {}: {}", displayable_path(path_in), exc) + return None def im_getsize(artresizer, path_in): @@ -192,11 +193,12 @@ def im_getsize(artresizer, path_in): 'getting size with command {}:\n{}', exc.returncode, cmd, exc.output.strip() ) - return + return None try: return tuple(map(int, out.split(b' '))) except IndexError: log.warning('Could not understand IM output: {0!r}', out) + return None BACKEND_GET_SIZE = { @@ -347,7 +349,7 @@ def im_compare(artresizer, im1, im2, compare_threshold): convert_proc.returncode, convert_stderr, ) - return + return None # Check the compare output. stdout, stderr = compare_proc.communicate() @@ -355,7 +357,7 @@ def im_compare(artresizer, im1, im2, compare_threshold): if compare_proc.returncode != 1: log.debug('ImageMagick compare failed: {0}, {1}', displayable_path(im2), displayable_path(im1)) - return + return None out_str = stderr else: out_str = stdout @@ -364,7 +366,7 @@ def im_compare(artresizer, im1, im2, compare_threshold): phash_diff = float(out_str) except ValueError: log.debug('IM output is not a number: {0!r}', out_str) - return + return None log.debug('ImageMagick compare score: {0}', phash_diff) return phash_diff <= compare_threshold @@ -471,6 +473,7 @@ class ArtResizer(metaclass=Shareable): if self.local: func = BACKEND_GET_SIZE[self.method[0]] return func(self, path_in) + return None def get_format(self, path_in): """Returns the format of the image as a string. @@ -480,6 +483,7 @@ class ArtResizer(metaclass=Shareable): if self.local: func = BACKEND_GET_FORMAT[self.method[0]] return func(self, path_in) + return None def reformat(self, path_in, new_format, deinterlaced=True): """Converts image to desired format, updating its extension, but @@ -524,6 +528,7 @@ class ArtResizer(metaclass=Shareable): if self.local: func = BACKEND_COMPARE[self.method[0]] return func(self, im1, im2, compare_threshold) + return None @staticmethod def _check_method():