From 7cd651b970113379026a4da069f5dddaeb6bccad Mon Sep 17 00:00:00 2001 From: Jann Stute Date: Wed, 26 Nov 2025 14:38:29 +0100 Subject: [PATCH] fix: pyright errors in blender_renderer.py --- src/tagstudio/qt/previews/renderer.py | 24 +++++++------------ .../qt/previews/vendored/blender_renderer.py | 6 +++-- src/tagstudio/qt/thumb_grid_layout.py | 2 +- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/tagstudio/qt/previews/renderer.py b/src/tagstudio/qt/previews/renderer.py index 566ab7aed..90bf7baaa 100644 --- a/src/tagstudio/qt/previews/renderer.py +++ b/src/tagstudio/qt/previews/renderer.py @@ -780,25 +780,17 @@ def _blender(filepath: Path) -> Image.Image | None: ) im: Image.Image | None = None try: - blend_image = blend_thumb(str(filepath)) - - bg = Image.new("RGB", blend_image.size, color=bg_color) - bg.paste(blend_image, mask=blend_image.getchannel(3)) - im = bg - - except ( - AttributeError, - UnidentifiedImageError, - TypeError, - ) as e: - if str(e) == "expected string or buffer": + if (blend_image := blend_thumb(str(filepath))) is not None: + bg = Image.new("RGB", blend_image.size, color=bg_color) + bg.paste(blend_image, mask=blend_image.getchannel(3)) + im = bg + else: logger.info( f"[ThumbRenderer][BLENDER][INFO] {filepath.name} " - f"Doesn't have an embedded thumbnail. ({type(e).__name__})" + "Doesn't have an embedded thumbnail." ) - - else: - logger.error("Couldn't render thumbnail", filepath=filepath, error=type(e).__name__) + except Exception as e: + logger.error("Couldn't render thumbnail", filepath=filepath, error=type(e).__name__) return im @staticmethod diff --git a/src/tagstudio/qt/previews/vendored/blender_renderer.py b/src/tagstudio/qt/previews/vendored/blender_renderer.py index 012c1503d..10e059e10 100644 --- a/src/tagstudio/qt/previews/vendored/blender_renderer.py +++ b/src/tagstudio/qt/previews/vendored/blender_renderer.py @@ -32,7 +32,7 @@ from PIL import Image, ImageOps -def blend_extract_thumb(path): +def blend_extract_thumb(path) -> tuple[bytes | None, int, int]: rend = b"REND" test = b"TEST" @@ -97,8 +97,10 @@ def blend_extract_thumb(path): return image_buffer, x, y -def blend_thumb(file_in): +def blend_thumb(file_in) -> Image.Image | None: buf, width, height = blend_extract_thumb(file_in) + if buf is None: + return None image = Image.frombuffer( "RGBA", (width, height), diff --git a/src/tagstudio/qt/thumb_grid_layout.py b/src/tagstudio/qt/thumb_grid_layout.py index 27ad31145..5347fc882 100644 --- a/src/tagstudio/qt/thumb_grid_layout.py +++ b/src/tagstudio/qt/thumb_grid_layout.py @@ -383,7 +383,7 @@ def hasHeightForWidth(self) -> bool: @override def itemAt(self, index: int) -> QLayoutItem: if index >= len(self._items): - return None + return None # pyright: ignore[reportReturnType] return self._items[index] @override