Flatbuffer structs have very strict typing
Closed this issue · 4 comments
The recent optimizations/rewrites resulted in stricter typing, which is uncharacteristic for Python.
For example, the following
controller.throttle = 1
results in this error:
TypeError: argument 'throttle': 'int' object cannot be converted to 'PyFloat'
while this works, of course:
controller.throttle = 1.0
Correct - recently, in order to optimize access times, I made the structs store the raw PyFloats. This is because before, every time you accessed one of those values, the PyFloat would have to be created on the fly - which was slow.
However, if I implement custom setters, we can get the type coercion back while still storing PyFloats for the better access times. Setting values will be slightly slower, but imo it's worth it and there aren't many places where you would directly set numbers in flatbuffers anyways. Most big structs that are interfaced with are read-only.
I can probably get this done by the end of the day, it shouldn't be hard.
However, if I implement custom setters, we can get the type coercion back while still storing PyFloats for the better access times. Setting values will be slightly slower, but imo it's worth it and there aren't many places where you would directly set numbers in flatbuffers anyways. Most big structs that are interfaced with are read-only.
I agree with that assessment. Cool 👍

