When a vector of strings is used, the generated code does not correctly decode into a string type and instead leaves the data as bytes (which is counter to the type hint).
Schema:
table test {
vec_of_string: [string];
single_string: string;
}
root_type test;
compiled with: ./build/flatc --python --python-version 3.12 --python-typing --gen-object-api --python-decode-obj-api-strings -o /tmp/blah/ strings.fbs
resulting code:
class testT(object):
# testT
def __init__(self):
self.vecOfString = None # type: Optional[List[Optional[str]]]
self.singleString = None # type: Optional[str]
...
This is correct, though I would question if it shouldn't be Optional[List[str]] instead. (since the .pyi generates typing.List[str] not str | None like the single case)
# testT
def _UnPack(self, test):
if test is None:
return
if not test.VecOfStringIsNone():
self.vecOfString = []
for i in range(test.VecOfStringLength()):
self.vecOfString.append(test.VecOfString(i))
self.singleString = test.SingleString()
if self.singleString is not None:
self.singleString = self.singleString.decode('utf-8')
This is incorrect. self.vecOfString.append(test.VecOfString(i)) should be self.vecOfString.append(test.VecOfString(i)).decode('utf-8'). If it's actually optional, I guess it should do a None check first. But regardless it should be decoding to match the type hint.
When a vector of strings is used, the generated code does not correctly decode into a string type and instead leaves the data as bytes (which is counter to the type hint).
Schema:
compiled with:
./build/flatc --python --python-version 3.12 --python-typing --gen-object-api --python-decode-obj-api-strings -o /tmp/blah/ strings.fbsresulting code:
This is correct, though I would question if it shouldn't be
Optional[List[str]]instead. (since the .pyi generatestyping.List[str]notstr | Nonelike the single case)This is incorrect.
self.vecOfString.append(test.VecOfString(i))should beself.vecOfString.append(test.VecOfString(i)).decode('utf-8'). If it's actually optional, I guess it should do a None check first. But regardless it should be decoding to match the type hint.