Skip to content

Commit 44b07dc

Browse files
committed
Remove list subscripts and update flatbuffers #4
1 parent b05650c commit 44b07dc

File tree

5 files changed

+10
-22
lines changed

5 files changed

+10
-22
lines changed

objectbox/model/entity.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def fill_properties(self):
8585
def get_value(self, object, prop: Property):
8686
# in case value is not overwritten on the object, it's the Property object itself (= as defined in the Class)
8787
val = getattr(object, prop._name)
88-
if prop._py_type == list[int] or prop._py_type == list[float]:
88+
if prop._py_type == list:
8989
if (val == np.array(prop)).all():
9090
return prop._py_type()
9191
elif prop._py_type == np.ndarray:
@@ -161,28 +161,20 @@ def unmarshal(self, data: bytes):
161161
# access the FB byte vector information
162162
start = table.Vector(o)
163163
size = table.VectorLen(o)
164-
165164
# slice the vector as a requested type
166165
val = prop._py_type(table.Bytes[start:start+size])
167166
elif prop._ob_type == OBXPropertyType_IntVector:
168167
val = table.GetVectorAsNumpy(flatbuffers.number_types.Int32Flags, o)
169-
if prop._py_type == list[int]:
170-
val = val.tolist()
171168
elif prop._ob_type == OBXPropertyType_LongVector:
172169
val = table.GetVectorAsNumpy(flatbuffers.number_types.Int64Flags, o)
173-
if prop._py_type == list[int]:
174-
val = val.tolist()
175170
elif prop._ob_type == OBXPropertyType_FloatVector:
176171
val = table.GetVectorAsNumpy(flatbuffers.number_types.Float32Flags, o)
177-
if prop._py_type == list[float]:
178-
val = val.tolist()
179172
elif prop._ob_type == OBXPropertyType_DoubleVector:
180173
val = table.GetVectorAsNumpy(flatbuffers.number_types.Float64Flags, o)
181-
if prop._py_type == list[float]:
182-
val = val.tolist()
183174
else:
184175
val = table.Get(prop._fb_type, o + table.Pos)
185-
176+
if prop._py_type == list:
177+
val = val.tolist()
186178
setattr(obj, prop._name, val)
187179
return obj
188180

objectbox/model/properties.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,7 @@ def __determine_ob_type(self) -> OBXPropertyType:
8686
return OBXPropertyType_Long
8787
elif ts == bytes: # or ts == bytearray: might require further tests on read objects due to mutability
8888
return OBXPropertyType_ByteVector
89-
elif ts == list[int]:
90-
return OBXPropertyType_LongVector
91-
elif ts == list[float]:
92-
return OBXPropertyType_DoubleVector
93-
elif ts == np.ndarray:
89+
elif ts == list or ts == np.ndarray:
9490
return OBXPropertyType_DoubleVector
9591
elif ts == float:
9692
return OBXPropertyType_Double

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pip
22
wheel
3-
flatbuffers==2.0
3+
flatbuffers==23.5.26
44
pytest>=4.4.1
55
twine
66
numpy

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
],
4747

4848
install_requires=[
49-
'flatbuffers==2.0',
49+
'flatbuffers==23.5.26',
5050
],
5151

5252
packages=setuptools.find_packages(),

tests/model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class TestEntity:
1818
longs = Property(np.ndarray, type=PropertyType.longVector, id=12, uid=1012)
1919
floats = Property(np.ndarray, type=PropertyType.floatVector, id=13, uid=1013)
2020
doubles = Property(np.ndarray, type=PropertyType.doubleVector, id=14, uid=1014)
21-
ints_list = Property(list[int], type=PropertyType.intVector, id=15, uid=1015)
22-
longs_list = Property(list[int], type=PropertyType.longVector, id=16, uid=1016)
23-
floats_list = Property(list[float], type=PropertyType.floatVector, id=17, uid=1017)
24-
doubles_list = Property(list[float], type=PropertyType.doubleVector, id=18, uid=1018)
21+
ints_list = Property(list, type=PropertyType.intVector, id=15, uid=1015)
22+
longs_list = Property(list, type=PropertyType.longVector, id=16, uid=1016)
23+
floats_list = Property(list, type=PropertyType.floatVector, id=17, uid=1017)
24+
doubles_list = Property(list, type=PropertyType.doubleVector, id=18, uid=1018)
2525
transient = "" # not "Property" so it's not stored
2626

2727
def __init__(self, string: str = ""):

0 commit comments

Comments
 (0)