Skip to content

Commit c91cad6

Browse files
committed
restructured code
1 parent 5a2f84d commit c91cad6

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

sourcehold/structure_tools/DataProperty.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import cast
12
from sourcehold.structure_tools import _resolve_cls_as_type, create_structure_from_buffer
23

34

@@ -107,6 +108,7 @@ def deserialize_from_buffer(self, buf: Buffer, **kwargs):
107108
if self.array_size == "*":
108109
s = struct.calcsize(self.type)
109110
r = []
111+
raise Exception("fixme: do we have break_array?")
110112
while not self.break_array(buf):
111113
r.append(struct.unpack(self.type, buf.read(s))[0])
112114
#return r
@@ -128,17 +130,18 @@ def deserialize_from_buffer(self, buf: Buffer, **kwargs):
128130
return r
129131
elif self.type.__class__ == type:
130132
if self.array_size == 0:
131-
r = create_structure_from_buffer(self.type, buf, **kwargs)
133+
r = create_structure_from_buffer(cast(type, self.type), buf, **kwargs)
132134
return r
133135
else:
134136
if self.array_size == "*":
135137
s = struct.calcsize(self.type)
136138
r = []
139+
raise Exception("fixme: do we have break_array?")
137140
while not self.break_array(buf):
138141
r.append(create_structure_from_buffer(self.type, buf, **kwargs))
139142
return r
140143
elif self.array_size.__class__ == int:
141-
r = [create_structure_from_buffer(self.type, buf, **kwargs) for i in range(self.array_size)]
144+
r = [create_structure_from_buffer(cast(type, self.type), buf, **kwargs) for i in range(self.array_size)]
142145
return r
143146
elif self.array_size.__class__.__name__ == 'function':
144147
raise NotImplementedError()

sourcehold/structure_tools/Field.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def serialize_to_buffer(self, obj, buf: Buffer):
6666
buf.write(r)
6767
else:
6868
if self.array_size == "*":
69-
for o in self.__get__(cast(Iterable, obj)):
69+
obj = cast(Iterable, obj)
70+
for o in self.__get__(obj):
7071
buf.write(struct.pack(self.type, o))
7172
elif self.array_size.__class__ == int:
7273
for o in self.__get__(obj):

sourcehold/structure_tools/Structure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self):
2121
# self.fields[key].fset(self, value)
2222

2323
@classmethod
24-
def get_fields(cls) -> dict:
24+
def get_fields(cls) -> dict[str, Field]:
2525
fields = {}
2626

2727
tree = list(cls.__mro__)

0 commit comments

Comments
 (0)