fix: pyright errors in blender_renderer.py (#1236)

This commit is contained in:
Jann Stute
2026-01-22 07:47:29 +01:00
committed by GitHub
parent 97c9d34186
commit 785959ec24
3 changed files with 13 additions and 19 deletions

View File

@@ -790,25 +790,17 @@ class ThumbRenderer(QObject):
)
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

View File

@@ -32,7 +32,7 @@ from io import BufferedReader
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),

View File

@@ -383,7 +383,7 @@ class ThumbGridLayout(QLayout):
@override
def itemAt(self, index: int) -> QLayoutItem:
if index >= len(self._items):
return None
return None # pyright: ignore[reportReturnType]
return self._items[index]
@override