Skip to content

Commit 785959e

Browse files
fix: pyright errors in blender_renderer.py (#1236)
1 parent 97c9d34 commit 785959e

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

src/tagstudio/qt/previews/renderer.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -790,25 +790,17 @@ def _blender(filepath: Path) -> Image.Image | None:
790790
)
791791
im: Image.Image | None = None
792792
try:
793-
blend_image = blend_thumb(str(filepath))
794-
795-
bg = Image.new("RGB", blend_image.size, color=bg_color)
796-
bg.paste(blend_image, mask=blend_image.getchannel(3))
797-
im = bg
798-
799-
except (
800-
AttributeError,
801-
UnidentifiedImageError,
802-
TypeError,
803-
) as e:
804-
if str(e) == "expected string or buffer":
793+
if (blend_image := blend_thumb(str(filepath))) is not None:
794+
bg = Image.new("RGB", blend_image.size, color=bg_color)
795+
bg.paste(blend_image, mask=blend_image.getchannel(3))
796+
im = bg
797+
else:
805798
logger.info(
806799
f"[ThumbRenderer][BLENDER][INFO] {filepath.name} "
807-
f"Doesn't have an embedded thumbnail. ({type(e).__name__})"
800+
"Doesn't have an embedded thumbnail."
808801
)
809-
810-
else:
811-
logger.error("Couldn't render thumbnail", filepath=filepath, error=type(e).__name__)
802+
except Exception as e:
803+
logger.error("Couldn't render thumbnail", filepath=filepath, error=type(e).__name__)
812804
return im
813805

814806
@staticmethod

src/tagstudio/qt/previews/vendored/blender_renderer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from PIL import Image, ImageOps
3333

3434

35-
def blend_extract_thumb(path):
35+
def blend_extract_thumb(path) -> tuple[bytes | None, int, int]:
3636
rend = b"REND"
3737
test = b"TEST"
3838

@@ -97,8 +97,10 @@ def blend_extract_thumb(path):
9797
return image_buffer, x, y
9898

9999

100-
def blend_thumb(file_in):
100+
def blend_thumb(file_in) -> Image.Image | None:
101101
buf, width, height = blend_extract_thumb(file_in)
102+
if buf is None:
103+
return None
102104
image = Image.frombuffer(
103105
"RGBA",
104106
(width, height),

src/tagstudio/qt/thumb_grid_layout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def hasHeightForWidth(self) -> bool:
383383
@override
384384
def itemAt(self, index: int) -> QLayoutItem:
385385
if index >= len(self._items):
386-
return None
386+
return None # pyright: ignore[reportReturnType]
387387
return self._items[index]
388388

389389
@override

0 commit comments

Comments
 (0)