MemoryResolver.resolve() returns bytearray slices, which is ultimately what array_impl.to_bytes() uses. Python 3.13 enforces that __bytes__ must return bytes, not bytearray, so this error turns up
File "libdestruct/common/obj.py", line 136, in __bytes__
return self.to_bytes()
File "libdestruct/common/array/array_impl.py", line 63, in to_bytes
return b"".join(bytes(x) for x in self)
TypeError: __bytes__ returned non-bytes (type bytearray)
Minimal script derived from what I was trying to do:
from libdestruct import inflater
from libdestruct.c.struct_parser import definition_to_type
MyStruct = definition_to_type("""
struct Foo {
char name[8];
};
""")
lib = inflater(bytearray(b"AAAAAAAA"))
provola = lib.inflate(MyStruct, 0)
bytes(provola)
Fix: memory_resolver.py:48:
- return self.memory[address : address + size]
+ return bytes(self.memory[address : address + size])
MemoryResolver.resolve()returnsbytearrayslices, which is ultimately whatarray_impl.to_bytes()uses. Python 3.13 enforces that__bytes__must returnbytes, notbytearray, so this error turns upMinimal script derived from what I was trying to do:
Fix:
memory_resolver.py:48: