From 79c8589bfc376aab5dbaec244f25afdb27af8ba3 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 28 Jul 2025 15:32:57 +0200 Subject: [PATCH] Add additional annotations to avoid typing issues (#92897) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BlendFileBlock attributes: Explicit annotation on BlendFileBlock are needed because otherwise e.g. `block.add_old` type was imprecisely inferred from the assignments as `int | Any`, where `Any` comes from `.unpack` returning `tuple[Any, ...]`. Ideally unpack should be somehow connected to the returned types, but this solution should work for now just to avoid typing errors. dna_io - add some missing annotations: Some annotations were needed to ensure `block.code` will be inferred as `bytes` and not `bytes | Unknown`. Reviewed-on: https://projects.blender.org/blender/blender-asset-tracer/pulls/92897 Reviewed-by: Sybren A. Stüvel --- blender_asset_tracer/blendfile/__init__.py | 6 ++++++ blender_asset_tracer/blendfile/dna_io.py | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/blender_asset_tracer/blendfile/__init__.py b/blender_asset_tracer/blendfile/__init__.py index e09ce3f..3b23c81 100644 --- a/blender_asset_tracer/blendfile/__init__.py +++ b/blender_asset_tracer/blendfile/__init__.py @@ -447,6 +447,12 @@ class BlendFileBlock: old_structure = struct.Struct(b"4sI") """old blend files ENDB block structure""" + # Explicitly annotate to avoid `Any` from `.unpack()`. + size: int + addr_old: int + sdna_index: int + count: int + def __init__(self, bfile: BlendFile) -> None: self.bfile = bfile diff --git a/blender_asset_tracer/blendfile/dna_io.py b/blender_asset_tracer/blendfile/dna_io.py index d675b6b..9399942 100644 --- a/blender_asset_tracer/blendfile/dna_io.py +++ b/blender_asset_tracer/blendfile/dna_io.py @@ -204,17 +204,17 @@ class EndianIO: return fileobj.write(to_write) @classmethod - def read_bytes0(cls, fileobj, length): + def read_bytes0(cls, fileobj: typing.IO[bytes], length: int) -> bytes: data = fileobj.read(length) return cls.read_data0(data) @classmethod - def read_data0_offset(cls, data, offset): + def read_data0_offset(cls, data: bytes, offset: int) -> bytes: add = data.find(b"\0", offset) - offset return data[offset : offset + add] @classmethod - def read_data0(cls, data): + def read_data0(cls, data: bytes) -> bytes: add = data.find(b"\0") if add < 0: return data