Add additional annotations to avoid typing issues (#92897)
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 <sybren@blender.org>
This commit is contained in:
parent
899f361fcf
commit
79c8589bfc
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user