diff options
author | Max Burke <max@urbanlogiq.com> | 2023-04-28 09:38:29 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-28 09:38:29 -0700 |
commit | a397dd7e8c3137fecc8b686b3efb5c31bf1d1b1e (patch) | |
tree | d9841de95dff3516df30bd0959a51d332eb79f69 | |
parent | 6eae49a79a1ac30c88255a9bea9c344589f7249d (diff) | |
download | flatbuffers-a397dd7e8c3137fecc8b686b3efb5c31bf1d1b1e.tar.gz flatbuffers-a397dd7e8c3137fecc8b686b3efb5c31bf1d1b1e.tar.bz2 flatbuffers-a397dd7e8c3137fecc8b686b3efb5c31bf1d1b1e.zip |
Optionally generate Python type annotations (#7858)
* optionally generate type prefixes and suffixes for python code
* fix codegen error when qualified name is empty
* WIP: Python typing
* more progress towards python typing
* Further iterate on Python generated code typing
* clang-format
* Regenerate code
* add documentation for Python type annotations option
* generate code with Python type annotations
* handle forward references
* clang-format
35 files changed, 1293 insertions, 977 deletions
diff --git a/grpc/examples/python/greeter/models/HelloReply.py b/grpc/examples/python/greeter/models/HelloReply.py index f1082fa2..bf182fc8 100644 --- a/grpc/examples/python/greeter/models/HelloReply.py +++ b/grpc/examples/python/greeter/models/HelloReply.py @@ -32,16 +32,16 @@ class HelloReply(object): return None def HelloReplyStart(builder): - return builder.StartObject(1) + builder.StartObject(1) def Start(builder): - return HelloReplyStart(builder) + HelloReplyStart(builder) def HelloReplyAddMessage(builder, message): - return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(message), 0) + builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(message), 0) -def AddMessage(builder, message): - return HelloReplyAddMessage(builder, message) +def AddMessage(builder: flatbuffers.Builder, message: int): + HelloReplyAddMessage(builder, message) def HelloReplyEnd(builder): return builder.EndObject() diff --git a/grpc/examples/python/greeter/models/HelloRequest.py b/grpc/examples/python/greeter/models/HelloRequest.py index b295369e..9df6b22c 100644 --- a/grpc/examples/python/greeter/models/HelloRequest.py +++ b/grpc/examples/python/greeter/models/HelloRequest.py @@ -32,16 +32,16 @@ class HelloRequest(object): return None def HelloRequestStart(builder): - return builder.StartObject(1) + builder.StartObject(1) def Start(builder): - return HelloRequestStart(builder) + HelloRequestStart(builder) def HelloRequestAddName(builder, name): - return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) -def AddName(builder, name): - return HelloRequestAddName(builder, name) +def AddName(builder: flatbuffers.Builder, name: int): + HelloRequestAddName(builder, name) def HelloRequestEnd(builder): return builder.EndObject() diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index bee67274..ced2049d 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -698,6 +698,7 @@ struct IDLOptions { bool require_json_eof; bool keep_proto_id; bool python_no_type_prefix_suffix; + bool python_typing; ProtoIdGapAction proto_id_gap_action; // Possible options for the more general generator below. @@ -808,6 +809,7 @@ struct IDLOptions { require_json_eof(true), keep_proto_id(false), python_no_type_prefix_suffix(false), + python_typing(false), proto_id_gap_action(ProtoIdGapAction::WARNING), mini_reflect(IDLOptions::kNone), require_explicit_ids(false), diff --git a/python/flatbuffers/reflection/Enum.py b/python/flatbuffers/reflection/Enum.py index bd2a7b33..fd4c410a 100644 --- a/python/flatbuffers/reflection/Enum.py +++ b/python/flatbuffers/reflection/Enum.py @@ -42,7 +42,7 @@ class Enum(object): x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 x = self._tab.Indirect(x) - from reflection.EnumVal import EnumVal + from .reflection.EnumVal import EnumVal obj = EnumVal() obj.Init(self._tab.Bytes, x) return obj @@ -72,7 +72,7 @@ class Enum(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) if o != 0: x = self._tab.Indirect(o + self._tab.Pos) - from reflection.Type import Type + from .reflection.Type import Type obj = Type() obj.Init(self._tab.Bytes, x) return obj @@ -85,7 +85,7 @@ class Enum(object): x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 x = self._tab.Indirect(x) - from reflection.KeyValue import KeyValue + from .reflection.KeyValue import KeyValue obj = KeyValue() obj.Init(self._tab.Bytes, x) return obj @@ -132,70 +132,70 @@ class Enum(object): return None def EnumStart(builder): - return builder.StartObject(7) + builder.StartObject(7) def Start(builder): - return EnumStart(builder) + EnumStart(builder) def EnumAddName(builder, name): - return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) -def AddName(builder, name): - return EnumAddName(builder, name) +def AddName(builder: flatbuffers.Builder, name: int): + EnumAddName(builder, name) def EnumAddValues(builder, values): - return builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(values), 0) + builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(values), 0) -def AddValues(builder, values): - return EnumAddValues(builder, values) +def AddValues(builder: flatbuffers.Builder, values: int): + EnumAddValues(builder, values) def EnumStartValuesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartValuesVector(builder, numElems): +def StartValuesVector(builder, numElems: int) -> int: return EnumStartValuesVector(builder, numElems) def EnumAddIsUnion(builder, isUnion): - return builder.PrependBoolSlot(2, isUnion, 0) + builder.PrependBoolSlot(2, isUnion, 0) -def AddIsUnion(builder, isUnion): - return EnumAddIsUnion(builder, isUnion) +def AddIsUnion(builder: flatbuffers.Builder, isUnion: bool): + EnumAddIsUnion(builder, isUnion) def EnumAddUnderlyingType(builder, underlyingType): - return builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(underlyingType), 0) + builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(underlyingType), 0) -def AddUnderlyingType(builder, underlyingType): - return EnumAddUnderlyingType(builder, underlyingType) +def AddUnderlyingType(builder: flatbuffers.Builder, underlyingType: int): + EnumAddUnderlyingType(builder, underlyingType) def EnumAddAttributes(builder, attributes): - return builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) + builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) -def AddAttributes(builder, attributes): - return EnumAddAttributes(builder, attributes) +def AddAttributes(builder: flatbuffers.Builder, attributes: int): + EnumAddAttributes(builder, attributes) def EnumStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartAttributesVector(builder, numElems): +def StartAttributesVector(builder, numElems: int) -> int: return EnumStartAttributesVector(builder, numElems) def EnumAddDocumentation(builder, documentation): - return builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) + builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) -def AddDocumentation(builder, documentation): - return EnumAddDocumentation(builder, documentation) +def AddDocumentation(builder: flatbuffers.Builder, documentation: int): + EnumAddDocumentation(builder, documentation) def EnumStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartDocumentationVector(builder, numElems): +def StartDocumentationVector(builder, numElems: int) -> int: return EnumStartDocumentationVector(builder, numElems) def EnumAddDeclarationFile(builder, declarationFile): - return builder.PrependUOffsetTRelativeSlot(6, flatbuffers.number_types.UOffsetTFlags.py_type(declarationFile), 0) + builder.PrependUOffsetTRelativeSlot(6, flatbuffers.number_types.UOffsetTFlags.py_type(declarationFile), 0) -def AddDeclarationFile(builder, declarationFile): - return EnumAddDeclarationFile(builder, declarationFile) +def AddDeclarationFile(builder: flatbuffers.Builder, declarationFile: int): + EnumAddDeclarationFile(builder, declarationFile) def EnumEnd(builder): return builder.EndObject() diff --git a/python/flatbuffers/reflection/EnumVal.py b/python/flatbuffers/reflection/EnumVal.py index 7019ec46..207dd843 100644 --- a/python/flatbuffers/reflection/EnumVal.py +++ b/python/flatbuffers/reflection/EnumVal.py @@ -47,7 +47,7 @@ class EnumVal(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) if o != 0: x = self._tab.Indirect(o + self._tab.Pos) - from reflection.Type import Type + from .reflection.Type import Type obj = Type() obj.Init(self._tab.Bytes, x) return obj @@ -80,7 +80,7 @@ class EnumVal(object): x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 x = self._tab.Indirect(x) - from reflection.KeyValue import KeyValue + from .reflection.KeyValue import KeyValue obj = KeyValue() obj.Init(self._tab.Bytes, x) return obj @@ -99,51 +99,51 @@ class EnumVal(object): return o == 0 def EnumValStart(builder): - return builder.StartObject(6) + builder.StartObject(6) def Start(builder): - return EnumValStart(builder) + EnumValStart(builder) def EnumValAddName(builder, name): - return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) -def AddName(builder, name): - return EnumValAddName(builder, name) +def AddName(builder: flatbuffers.Builder, name: int): + EnumValAddName(builder, name) def EnumValAddValue(builder, value): - return builder.PrependInt64Slot(1, value, 0) + builder.PrependInt64Slot(1, value, 0) -def AddValue(builder, value): - return EnumValAddValue(builder, value) +def AddValue(builder: flatbuffers.Builder, value: int): + EnumValAddValue(builder, value) def EnumValAddUnionType(builder, unionType): - return builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(unionType), 0) + builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(unionType), 0) -def AddUnionType(builder, unionType): - return EnumValAddUnionType(builder, unionType) +def AddUnionType(builder: flatbuffers.Builder, unionType: int): + EnumValAddUnionType(builder, unionType) def EnumValAddDocumentation(builder, documentation): - return builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) + builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) -def AddDocumentation(builder, documentation): - return EnumValAddDocumentation(builder, documentation) +def AddDocumentation(builder: flatbuffers.Builder, documentation: int): + EnumValAddDocumentation(builder, documentation) def EnumValStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartDocumentationVector(builder, numElems): +def StartDocumentationVector(builder, numElems: int) -> int: return EnumValStartDocumentationVector(builder, numElems) def EnumValAddAttributes(builder, attributes): - return builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) + builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) -def AddAttributes(builder, attributes): - return EnumValAddAttributes(builder, attributes) +def AddAttributes(builder: flatbuffers.Builder, attributes: int): + EnumValAddAttributes(builder, attributes) def EnumValStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartAttributesVector(builder, numElems): +def StartAttributesVector(builder, numElems: int) -> int: return EnumValStartAttributesVector(builder, numElems) def EnumValEnd(builder): diff --git a/python/flatbuffers/reflection/Field.py b/python/flatbuffers/reflection/Field.py index a0e660fd..36ceb2bf 100644 --- a/python/flatbuffers/reflection/Field.py +++ b/python/flatbuffers/reflection/Field.py @@ -40,7 +40,7 @@ class Field(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) if o != 0: x = self._tab.Indirect(o + self._tab.Pos) - from reflection.Type import Type + from .reflection.Type import Type obj = Type() obj.Init(self._tab.Bytes, x) return obj @@ -102,7 +102,7 @@ class Field(object): x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 x = self._tab.Indirect(x) - from reflection.KeyValue import KeyValue + from .reflection.KeyValue import KeyValue obj = KeyValue() obj.Init(self._tab.Bytes, x) return obj @@ -156,100 +156,100 @@ class Field(object): return 0 def FieldStart(builder): - return builder.StartObject(13) + builder.StartObject(13) def Start(builder): - return FieldStart(builder) + FieldStart(builder) def FieldAddName(builder, name): - return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) -def AddName(builder, name): - return FieldAddName(builder, name) +def AddName(builder: flatbuffers.Builder, name: int): + FieldAddName(builder, name) def FieldAddType(builder, type): - return builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(type), 0) + builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(type), 0) -def AddType(builder, type): - return FieldAddType(builder, type) +def AddType(builder: flatbuffers.Builder, type: int): + FieldAddType(builder, type) def FieldAddId(builder, id): - return builder.PrependUint16Slot(2, id, 0) + builder.PrependUint16Slot(2, id, 0) -def AddId(builder, id): - return FieldAddId(builder, id) +def AddId(builder: flatbuffers.Builder, id: int): + FieldAddId(builder, id) def FieldAddOffset(builder, offset): - return builder.PrependUint16Slot(3, offset, 0) + builder.PrependUint16Slot(3, offset, 0) -def AddOffset(builder, offset): - return FieldAddOffset(builder, offset) +def AddOffset(builder: flatbuffers.Builder, offset: int): + FieldAddOffset(builder, offset) def FieldAddDefaultInteger(builder, defaultInteger): - return builder.PrependInt64Slot(4, defaultInteger, 0) + builder.PrependInt64Slot(4, defaultInteger, 0) -def AddDefaultInteger(builder, defaultInteger): - return FieldAddDefaultInteger(builder, defaultInteger) +def AddDefaultInteger(builder: flatbuffers.Builder, defaultInteger: int): + FieldAddDefaultInteger(builder, defaultInteger) def FieldAddDefaultReal(builder, defaultReal): - return builder.PrependFloat64Slot(5, defaultReal, 0.0) + builder.PrependFloat64Slot(5, defaultReal, 0.0) -def AddDefaultReal(builder, defaultReal): - return FieldAddDefaultReal(builder, defaultReal) +def AddDefaultReal(builder: flatbuffers.Builder, defaultReal: float): + FieldAddDefaultReal(builder, defaultReal) def FieldAddDeprecated(builder, deprecated): - return builder.PrependBoolSlot(6, deprecated, 0) + builder.PrependBoolSlot(6, deprecated, 0) -def AddDeprecated(builder, deprecated): - return FieldAddDeprecated(builder, deprecated) +def AddDeprecated(builder: flatbuffers.Builder, deprecated: bool): + FieldAddDeprecated(builder, deprecated) def FieldAddRequired(builder, required): - return builder.PrependBoolSlot(7, required, 0) + builder.PrependBoolSlot(7, required, 0) -def AddRequired(builder, required): - return FieldAddRequired(builder, required) +def AddRequired(builder: flatbuffers.Builder, required: bool): + FieldAddRequired(builder, required) def FieldAddKey(builder, key): - return builder.PrependBoolSlot(8, key, 0) + builder.PrependBoolSlot(8, key, 0) -def AddKey(builder, key): - return FieldAddKey(builder, key) +def AddKey(builder: flatbuffers.Builder, key: bool): + FieldAddKey(builder, key) def FieldAddAttributes(builder, attributes): - return builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) + builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) -def AddAttributes(builder, attributes): - return FieldAddAttributes(builder, attributes) +def AddAttributes(builder: flatbuffers.Builder, attributes: int): + FieldAddAttributes(builder, attributes) def FieldStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartAttributesVector(builder, numElems): +def StartAttributesVector(builder, numElems: int) -> int: return FieldStartAttributesVector(builder, numElems) def FieldAddDocumentation(builder, documentation): - return builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) + builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) -def AddDocumentation(builder, documentation): - return FieldAddDocumentation(builder, documentation) +def AddDocumentation(builder: flatbuffers.Builder, documentation: int): + FieldAddDocumentation(builder, documentation) def FieldStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartDocumentationVector(builder, numElems): +def StartDocumentationVector(builder, numElems: int) -> int: return FieldStartDocumentationVector(builder, numElems) def FieldAddOptional(builder, optional): - return builder.PrependBoolSlot(11, optional, 0) + builder.PrependBoolSlot(11, optional, 0) -def AddOptional(builder, optional): - return FieldAddOptional(builder, optional) +def AddOptional(builder: flatbuffers.Builder, optional: bool): + FieldAddOptional(builder, optional) def FieldAddPadding(builder, padding): - return builder.PrependUint16Slot(12, padding, 0) + builder.PrependUint16Slot(12, padding, 0) -def AddPadding(builder, padding): - return FieldAddPadding(builder, padding) +def AddPadding(builder: flatbuffers.Builder, padding: int): + FieldAddPadding(builder, padding) def FieldEnd(builder): return builder.EndObject() diff --git a/python/flatbuffers/reflection/KeyValue.py b/python/flatbuffers/reflection/KeyValue.py index 7b24a76e..fb9014c9 100644 --- a/python/flatbuffers/reflection/KeyValue.py +++ b/python/flatbuffers/reflection/KeyValue.py @@ -43,22 +43,22 @@ class KeyValue(object): return None def KeyValueStart(builder): - return builder.StartObject(2) + builder.StartObject(2) def Start(builder): - return KeyValueStart(builder) + KeyValueStart(builder) def KeyValueAddKey(builder, key): - return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(key), 0) + builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(key), 0) -def AddKey(builder, key): - return KeyValueAddKey(builder, key) +def AddKey(builder: flatbuffers.Builder, key: int): + KeyValueAddKey(builder, key) def KeyValueAddValue(builder, value): - return builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(value), 0) + builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(value), 0) -def AddValue(builder, value): - return KeyValueAddValue(builder, value) +def AddValue(builder: flatbuffers.Builder, value: int): + KeyValueAddValue(builder, value) def KeyValueEnd(builder): return builder.EndObject() diff --git a/python/flatbuffers/reflection/Object.py b/python/flatbuffers/reflection/Object.py index f890ffbc..139e0627 100644 --- a/python/flatbuffers/reflection/Object.py +++ b/python/flatbuffers/reflection/Object.py @@ -42,7 +42,7 @@ class Object(object): x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 x = self._tab.Indirect(x) - from reflection.Field import Field + from .reflection.Field import Field obj = Field() obj.Init(self._tab.Bytes, x) return obj @@ -88,7 +88,7 @@ class Object(object): x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 x = self._tab.Indirect(x) - from reflection.KeyValue import KeyValue + from .reflection.KeyValue import KeyValue obj = KeyValue() obj.Init(self._tab.Bytes, x) return obj @@ -135,76 +135,76 @@ class Object(object): return None def ObjectStart(builder): - return builder.StartObject(8) + builder.StartObject(8) def Start(builder): - return ObjectStart(builder) + ObjectStart(builder) def ObjectAddName(builder, name): - return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) -def AddName(builder, name): - return ObjectAddName(builder, name) +def AddName(builder: flatbuffers.Builder, name: int): + ObjectAddName(builder, name) def ObjectAddFields(builder, fields): - return builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(fields), 0) + builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(fields), 0) -def AddFields(builder, fields): - return ObjectAddFields(builder, fields) +def AddFields(builder: flatbuffers.Builder, fields: int): + ObjectAddFields(builder, fields) def ObjectStartFieldsVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartFieldsVector(builder, numElems): +def StartFieldsVector(builder, numElems: int) -> int: return ObjectStartFieldsVector(builder, numElems) def ObjectAddIsStruct(builder, isStruct): - return builder.PrependBoolSlot(2, isStruct, 0) + builder.PrependBoolSlot(2, isStruct, 0) -def AddIsStruct(builder, isStruct): - return ObjectAddIsStruct(builder, isStruct) +def AddIsStruct(builder: flatbuffers.Builder, isStruct: bool): + ObjectAddIsStruct(builder, isStruct) def ObjectAddMinalign(builder, minalign): - return builder.PrependInt32Slot(3, minalign, 0) + builder.PrependInt32Slot(3, minalign, 0) -def AddMinalign(builder, minalign): - return ObjectAddMinalign(builder, minalign) +def AddMinalign(builder: flatbuffers.Builder, minalign: int): + ObjectAddMinalign(builder, minalign) def ObjectAddBytesize(builder, bytesize): - return builder.PrependInt32Slot(4, bytesize, 0) + builder.PrependInt32Slot(4, bytesize, 0) -def AddBytesize(builder, bytesize): - return ObjectAddBytesize(builder, bytesize) +def AddBytesize(builder: flatbuffers.Builder, bytesize: int): + ObjectAddBytesize(builder, bytesize) def ObjectAddAttributes(builder, attributes): - return builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) + builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) -def AddAttributes(builder, attributes): - return ObjectAddAttributes(builder, attributes) +def AddAttributes(builder: flatbuffers.Builder, attributes: int): + ObjectAddAttributes(builder, attributes) def ObjectStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartAttributesVector(builder, numElems): +def StartAttributesVector(builder, numElems: int) -> int: return ObjectStartAttributesVector(builder, numElems) def ObjectAddDocumentation(builder, documentation): - return builder.PrependUOffsetTRelativeSlot(6, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) + builder.PrependUOffsetTRelativeSlot(6, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) -def AddDocumentation(builder, documentation): - return ObjectAddDocumentation(builder, documentation) +def AddDocumentation(builder: flatbuffers.Builder, documentation: int): + ObjectAddDocumentation(builder, documentation) def ObjectStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartDocumentationVector(builder, numElems): +def StartDocumentationVector(builder, numElems: int) -> int: return ObjectStartDocumentationVector(builder, numElems) def ObjectAddDeclarationFile(builder, declarationFile): - return builder.PrependUOffsetTRelativeSlot(7, flatbuffers.number_types.UOffsetTFlags.py_type(declarationFile), 0) + builder.PrependUOffsetTRelativeSlot(7, flatbuffers.number_types.UOffsetTFlags.py_type(declarationFile), 0) -def AddDeclarationFile(builder, declarationFile): - return ObjectAddDeclarationFile(builder, declarationFile) +def AddDeclarationFile(builder: flatbuffers.Builder, declarationFile: int): + ObjectAddDeclarationFile(builder, declarationFile) def ObjectEnd(builder): return builder.EndObject() diff --git a/python/flatbuffers/reflection/RPCCall.py b/python/flatbuffers/reflection/RPCCall.py index b126f04e..f78edec0 100644 --- a/python/flatbuffers/reflection/RPCCall.py +++ b/python/flatbuffers/reflection/RPCCall.py @@ -40,7 +40,7 @@ class RPCCall(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) if o != 0: x = self._tab.Indirect(o + self._tab.Pos) - from reflection.Object import Object + from .reflection.Object import Object obj = Object() obj.Init(self._tab.Bytes, x) return obj @@ -51,7 +51,7 @@ class RPCCall(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) if o != 0: x = self._tab.Indirect(o + self._tab.Pos) - from reflection.Object import Object + from .reflection.Object import Object obj = Object() obj.Init(self._tab.Bytes, x) return obj @@ -64,7 +64,7 @@ class RPCCall(object): x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 x = self._tab.Indirect(x) - from reflection.KeyValue import KeyValue + from .reflection.KeyValue import KeyValue obj = KeyValue() obj.Init(self._tab.Bytes, x) return obj @@ -103,51 +103,51 @@ class RPCCall(object): return o == 0 def RPCCallStart(builder): - return builder.StartObject(5) + builder.StartObject(5) def Start(builder): - return RPCCallStart(builder) + RPCCallStart(builder) def RPCCallAddName(builder, name): - return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) -def AddName(builder, name): - return RPCCallAddName(builder, name) +def AddName(builder: flatbuffers.Builder, name: int): + RPCCallAddName(builder, name) def RPCCallAddRequest(builder, request): - return builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(request), 0) + builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(request), 0) -def AddRequest(builder, request): - return RPCCallAddRequest(builder, request) +def AddRequest(builder: flatbuffers.Builder, request: int): + RPCCallAddRequest(builder, request) def RPCCallAddResponse(builder, response): - return builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(response), 0) + builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(response), 0) -def AddResponse(builder, response): - return RPCCallAddResponse(builder, response) +def AddResponse(builder: flatbuffers.Builder, response: int): + RPCCallAddResponse(builder, response) def RPCCallAddAttributes(builder, attributes): - return builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) + builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) -def AddAttributes(builder, attributes): - return RPCCallAddAttributes(builder, attributes) +def AddAttributes(builder: flatbuffers.Builder, attributes: int): + RPCCallAddAttributes(builder, attributes) def RPCCallStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartAttributesVector(builder, numElems): +def StartAttributesVector(builder, numElems: int) -> int: return RPCCallStartAttributesVector(builder, numElems) def RPCCallAddDocumentation(builder, documentation): - return builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) + builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) -def AddDocumentation(builder, documentation): - return RPCCallAddDocumentation(builder, documentation) +def AddDocumentation(builder: flatbuffers.Builder, documentation: int): + RPCCallAddDocumentation(builder, documentation) def RPCCallStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartDocumentationVector(builder, numElems): +def StartDocumentationVector(builder, numElems: int) -> int: return RPCCallStartDocumentationVector(builder, numElems) def RPCCallEnd(builder): diff --git a/python/flatbuffers/reflection/Schema.py b/python/flatbuffers/reflection/Schema.py index d7929a49..06df1a04 100644 --- a/python/flatbuffers/reflection/Schema.py +++ b/python/flatbuffers/reflection/Schema.py @@ -35,7 +35,7 @@ class Schema(object): x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 x = self._tab.Indirect(x) - from reflection.Object import Object + from .reflection.Object import Object obj = Object() obj.Init(self._tab.Bytes, x) return obj @@ -60,7 +60,7 @@ class Schema(object): x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 x = self._tab.Indirect(x) - from reflection.Enum import Enum + from .reflection.Enum import Enum obj = Enum() obj.Init(self._tab.Bytes, x) return obj @@ -97,7 +97,7 @@ class Schema(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) if o != 0: x = self._tab.Indirect(o + self._tab.Pos) - from reflection.Object import Object + from .reflection.Object import Object obj = Object() obj.Init(self._tab.Bytes, x) return obj @@ -110,7 +110,7 @@ class Schema(object): x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 x = self._tab.Indirect(x) - from reflection.Service import Service + from .reflection.Service import Service obj = Service() obj.Init(self._tab.Bytes, x) return obj @@ -144,7 +144,7 @@ class Schema(object): x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 x = self._tab.Indirect(x) - from reflection.SchemaFile import SchemaFile + from .reflection.SchemaFile import SchemaFile obj = SchemaFile() obj.Init(self._tab.Bytes, x) return obj @@ -163,81 +163,81 @@ class Schema(object): return o == 0 def SchemaStart(builder): - return builder.StartObject(8) + builder.StartObject(8) def Start(builder): - return SchemaStart(builder) + SchemaStart(builder) def SchemaAddObjects(builder, objects): - return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(objects), 0) + builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(objects), 0) -def AddObjects(builder, objects): - return SchemaAddObjects(builder, objects) +def AddObjects(builder: flatbuffers.Builder, objects: int): + SchemaAddObjects(builder, objects) def SchemaStartObjectsVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartObjectsVector(builder, numElems): +def StartObjectsVector(builder, numElems: int) -> int: return SchemaStartObjectsVector(builder, numElems) def SchemaAddEnums(builder, enums): - return builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(enums), 0) + builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(enums), 0) -def AddEnums(builder, enums): - return SchemaAddEnums(builder, enums) +def AddEnums(builder: flatbuffers.Builder, enums: int): + SchemaAddEnums(builder, enums) def SchemaStartEnumsVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartEnumsVector(builder, numElems): +def StartEnumsVector(builder, numElems: int) -> int: return SchemaStartEnumsVector(builder, numElems) def SchemaAddFileIdent(builder, fileIdent): - return builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(fileIdent), 0) + builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(fileIdent), 0) -def AddFileIdent(builder, fileIdent): - return SchemaAddFileIdent(builder, fileIdent) +def AddFileIdent(builder: flatbuffers.Builder, fileIdent: int): + SchemaAddFileIdent(builder, fileIdent) def SchemaAddFileExt(builder, fileExt): - return builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(fileExt), 0) + builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(fileExt), 0) -def AddFileExt(builder, fileExt): - return SchemaAddFileExt(builder, fileExt) +def AddFileExt(builder: flatbuffers.Builder, fileExt: int): + SchemaAddFileExt(builder, fileExt) def SchemaAddRootTable(builder, rootTable): - return builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(rootTable), 0) + builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(rootTable), 0) -def AddRootTable(builder, rootTable): - return SchemaAddRootTable(builder, rootTable) +def AddRootTable(builder: flatbuffers.Builder, rootTable: int): + SchemaAddRootTable(builder, rootTable) def SchemaAddServices(builder, services): - return builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(services), 0) + builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(services), 0) -def AddServices(builder, services): - return SchemaAddServices(builder, services) +def AddServices(builder: flatbuffers.Builder, services: int): + SchemaAddServices(builder, services) def SchemaStartServicesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartServicesVector(builder, numElems): +def StartServicesVector(builder, numElems: int) -> int: return SchemaStartServicesVector(builder, numElems) def SchemaAddAdvancedFeatures(builder, advancedFeatures): - return builder.PrependUint64Slot(6, advancedFeatures, 0) + builder.PrependUint64Slot(6, advancedFeatures, 0) -def AddAdvancedFeatures(builder, advancedFeatures): - return SchemaAddAdvancedFeatures(builder, advancedFeatures) +def AddAdvancedFeatures(builder: flatbuffers.Builder, advancedFeatures: int): + SchemaAddAdvancedFeatures(builder, advancedFeatures) def SchemaAddFbsFiles(builder, fbsFiles): - return builder.PrependUOffsetTRelativeSlot(7, flatbuffers.number_types.UOffsetTFlags.py_type(fbsFiles), 0) + builder.PrependUOffsetTRelativeSlot(7, flatbuffers.number_types.UOffsetTFlags.py_type(fbsFiles), 0) -def AddFbsFiles(builder, fbsFiles): - return SchemaAddFbsFiles(builder, fbsFiles) +def AddFbsFiles(builder: flatbuffers.Builder, fbsFiles: int): + SchemaAddFbsFiles(builder, fbsFiles) def SchemaStartFbsFilesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartFbsFilesVector(builder, numElems): +def StartFbsFilesVector(builder, numElems: int) -> int: return SchemaStartFbsFilesVector(builder, numElems) def SchemaEnd(builder): diff --git a/python/flatbuffers/reflection/SchemaFile.py b/python/flatbuffers/reflection/SchemaFile.py index d4c81786..009e7f2f 100644 --- a/python/flatbuffers/reflection/SchemaFile.py +++ b/python/flatbuffers/reflection/SchemaFile.py @@ -61,27 +61,27 @@ class SchemaFile(object): return o == 0 def SchemaFileStart(builder): - return builder.StartObject(2) + builder.StartObject(2) def Start(builder): - return SchemaFileStart(builder) + SchemaFileStart(builder) def SchemaFileAddFilename(builder, filename): - return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(filename), 0) + builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(filename), 0) -def AddFilename(builder, filename): - return SchemaFileAddFilename(builder, filename) +def AddFilename(builder: flatbuffers.Builder, filename: int): + SchemaFileAddFilename(builder, filename) def SchemaFileAddIncludedFilenames(builder, includedFilenames): - return builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(includedFilenames), 0) + builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(includedFilenames), 0) -def AddIncludedFilenames(builder, includedFilenames): - return SchemaFileAddIncludedFilenames(builder, includedFilenames) +def AddIncludedFilenames(builder: flatbuffers.Builder, includedFilenames: int): + SchemaFileAddIncludedFilenames(builder, includedFilenames) def SchemaFileStartIncludedFilenamesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartIncludedFilenamesVector(builder, numElems): +def StartIncludedFilenamesVector(builder, numElems: int) -> int: return SchemaFileStartIncludedFilenamesVector(builder, numElems) def SchemaFileEnd(builder): diff --git a/python/flatbuffers/reflection/Service.py b/python/flatbuffers/reflection/Service.py index eaec60af..eb8db7ef 100644 --- a/python/flatbuffers/reflection/Service.py +++ b/python/flatbuffers/reflection/Service.py @@ -42,7 +42,7 @@ class Service(object): x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 x = self._tab.Indirect(x) - from reflection.RPCCall import RPCCall + from .reflection.RPCCall import RPCCall obj = RPCCall() obj.Init(self._tab.Bytes, x) return obj @@ -67,7 +67,7 @@ class Service(object): x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 x = self._tab.Indirect(x) - from reflection.KeyValue import KeyValue + from .reflection.KeyValue import KeyValue obj = KeyValue() obj.Init(self._tab.Bytes, x) return obj @@ -114,58 +114,58 @@ class Service(object): return None def ServiceStart(builder): - return builder.StartObject(5) + builder.StartObject(5) def Start(builder): - return ServiceStart(builder) + ServiceStart(builder) def ServiceAddName(builder, name): - return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) -def AddName(builder, name): - return ServiceAddName(builder, name) +def AddName(builder: flatbuffers.Builder, name: int): + ServiceAddName(builder, name) def ServiceAddCalls(builder, calls): - return builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(calls), 0) + builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(calls), 0) -def AddCalls(builder, calls): - return ServiceAddCalls(builder, calls) +def AddCalls(builder: flatbuffers.Builder, calls: int): + ServiceAddCalls(builder, calls) def ServiceStartCallsVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartCallsVector(builder, numElems): +def StartCallsVector(builder, numElems: int) -> int: return ServiceStartCallsVector(builder, numElems) def ServiceAddAttributes(builder, attributes): - return builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) + builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) -def AddAttributes(builder, attributes): - return ServiceAddAttributes(builder, attributes) +def AddAttributes(builder: flatbuffers.Builder, attributes: int): + ServiceAddAttributes(builder, attributes) def ServiceStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartAttributesVector(builder, numElems): +def StartAttributesVector(builder, numElems: int) -> int: return ServiceStartAttributesVector(builder, numElems) def ServiceAddDocumentation(builder, documentation): - return builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) + builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) -def AddDocumentation(builder, documentation): - return ServiceAddDocumentation(builder, documentation) +def AddDocumentation(builder: flatbuffers.Builder, documentation: int): + ServiceAddDocumentation(builder, documentation) def ServiceStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartDocumentationVector(builder, numElems): +def StartDocumentationVector(builder, numElems: int) -> int: return ServiceStartDocumentationVector(builder, numElems) def ServiceAddDeclarationFile(builder, declarationFile): - return builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(declarationFile), 0) + builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(declarationFile), 0) -def AddDeclarationFile(builder, declarationFile): - return ServiceAddDeclarationFile(builder, declarationFile) +def AddDeclarationFile(builder: flatbuffers.Builder, declarationFile: int): + ServiceAddDeclarationFile(builder, declarationFile) def ServiceEnd(builder): return builder.EndObject() diff --git a/python/flatbuffers/reflection/Type.py b/python/flatbuffers/reflection/Type.py index eb58dd8a..76c08c48 100644 --- a/python/flatbuffers/reflection/Type.py +++ b/python/flatbuffers/reflection/Type.py @@ -73,46 +73,46 @@ class Type(object): return 0 def TypeStart(builder): - return builder.StartObject(6) + builder.StartObject(6) def Start(builder): - return TypeStart(builder) + TypeStart(builder) def TypeAddBaseType(builder, baseType): - return builder.PrependInt8Slot(0, baseType, 0) + builder.PrependInt8Slot(0, baseType, 0) -def AddBaseType(builder, baseType): - return TypeAddBaseType(builder, baseType) +def AddBaseType(builder: flatbuffers.Builder, baseType: int): + TypeAddBaseType(builder, baseType) def TypeAddElement(builder, element): - return builder.PrependInt8Slot(1, element, 0) + builder.PrependInt8Slot(1, element, 0) -def AddElement(builder, element): - return TypeAddElement(builder, element) +def AddElement(builder: flatbuffers.Builder, element: int): + TypeAddElement(builder, element) def TypeAddIndex(builder, index): - return builder.PrependInt32Slot(2, index, -1) + builder.PrependInt32Slot(2, index, -1) -def AddIndex(builder, index): - return TypeAddIndex(builder, index) +def AddIndex(builder: flatbuffers.Builder, index: int): + TypeAddIndex(builder, index) def TypeAddFixedLength(builder, fixedLength): - return builder.PrependUint16Slot(3, fixedLength, 0) + builder.PrependUint16Slot(3, fixedLength, 0) -def AddFixedLength(builder, fixedLength): - return TypeAddFixedLength(builder, fixedLength) +def AddFixedLength(builder: flatbuffers.Builder, fixedLength: int): + TypeAddFixedLength(builder, fixedLength) def TypeAddBaseSize(builder, baseSize): - return builder.PrependUint32Slot(4, baseSize, 4) + builder.PrependUint32Slot(4, baseSize, 4) -def AddBaseSize(builder, baseSize): - return TypeAddBaseSize(builder, baseSize) +def AddBaseSize(builder: flatbuffers.Builder, baseSize: int): + TypeAddBaseSize(builder, baseSize) def TypeAddElementSize(builder, elementSize): - return builder.PrependUint32Slot(5, elementSize, 0) + builder.PrependUint32Slot(5, elementSize, 0) -def AddElementSize(builder, elementSize): - return TypeAddElementSize(builder, elementSize) +def AddElementSize(builder: flatbuffers.Builder, elementSize: int): + TypeAddElementSize(builder, elementSize) def TypeEnd(builder): return builder.EndObject() diff --git a/python/py.typed b/python/py.typed new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/python/py.typed diff --git a/scripts/generate_code.py b/scripts/generate_code.py index 49dfe34e..6c18c7f8 100755 --- a/scripts/generate_code.py +++ b/scripts/generate_code.py @@ -103,7 +103,7 @@ JAVA_OPTS = ["--java"] KOTLIN_OPTS = ["--kotlin"] PHP_OPTS = ["--php"] DART_OPTS = ["--dart"] -PYTHON_OPTS = ["--python"] +PYTHON_OPTS = ["--python", "--python-typing"] BINARY_OPTS = ["-b", "--schema", "--bfbs-comments", "--bfbs-builtins"] PROTO_OPTS = ["--proto"] diff --git a/src/flatc.cpp b/src/flatc.cpp index 0e20a2f7..4a3ffb70 100644 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -252,6 +252,8 @@ const static FlatCOption flatc_options[] = { "Currently this is required to generate private types in Rust" }, { "", "python-no-type-prefix-suffix", "", "Skip emission of Python functions that are prefixed with typenames" }, + { "", "python-typing", "", + "Generate Python type annotations" }, { "", "file-names-only", "", "Print out generated file names without writing to the files"}, }; @@ -652,9 +654,11 @@ FlatCOptions FlatCompiler::ParseFromCommandLineArguments(int argc, opts.ts_no_import_ext = true; } else if (arg == "--no-leak-private-annotation") { opts.no_leak_private_annotations = true; - } else if (arg == "--python-no-type-prefix-suffix") { + } else if (arg == "--python-no-type-prefix-suffix") { opts.python_no_type_prefix_suffix = true; - } else if (arg == "--annotate-sparse-vectors") { + } else if (arg == "--python-typing") { + opts.python_typing = true; + } else if (arg == "--annotate-sparse-vectors") { options.annotate_include_vector_contents = false; } else if (arg == "--annotate") { if (++argi >= argc) Error("missing path following: " + arg, true); diff --git a/src/idl_gen_python.cpp b/src/idl_gen_python.cpp index 6c93b909..83d589ca 100644 --- a/src/idl_gen_python.cpp +++ b/src/idl_gen_python.cpp @@ -35,6 +35,9 @@ namespace python { namespace { +typedef std::pair<std::string, std::string> ImportMapEntry; +typedef std::set<ImportMapEntry> ImportMap; + static std::set<std::string> PythonKeywords() { return { "False", "None", "True", "and", "as", "assert", "break", "class", "continue", "def", "del", "elif", @@ -129,7 +132,11 @@ class PythonGenerator : public BaseGenerator { code += Indent + "@classmethod\n"; code += Indent + "def GetRootAs"; - code += "(cls, buf, offset=0):"; + if (parser_.opts.python_typing) { + code += "(cls, buf, offset: int = 0):"; + } else { + code += "(cls, buf, offset=0):"; + } code += "\n"; code += Indent + Indent; code += "n = flatbuffers.encode.Get"; @@ -156,7 +163,11 @@ class PythonGenerator : public BaseGenerator { auto &code = *code_ptr; GenReceiver(struct_def, code_ptr); - code += "Init(self, buf, pos):\n"; + if (parser_.opts.python_typing) { + code += "Init(self, buf: bytes, pos: int):\n"; + } else { + code += "Init(self, buf, pos):\n"; + } code += Indent + Indent + "self._tab = flatbuffers.table.Table(buf, pos)\n"; code += "\n"; } @@ -167,8 +178,11 @@ class PythonGenerator : public BaseGenerator { auto &code = *code_ptr; GenReceiver(struct_def, code_ptr); - code += namer_.Method(field) + "Length(self"; - code += "):"; + code += namer_.Method(field) + "Length(self)"; + if (parser_.opts.python_typing) { + code += " -> int"; + } + code += ":"; if(!IsArray(field.value.type)){ code += OffsetPrefix(field,false); code += GenIndents(3) + "return self._tab.VectorLen(o)"; @@ -184,8 +198,11 @@ class PythonGenerator : public BaseGenerator { auto &code = *code_ptr; GenReceiver(struct_def, code_ptr); - code += namer_.Method(field) + "IsNone(self"; - code += "):"; + code += namer_.Method(field) + "IsNone(self)"; + if (parser_.opts.python_typing) { + code += " -> bool"; + } + code += ":"; if(!IsArray(field.value.type)){ code += GenIndents(2) + "o = flatbuffers.number_types.UOffsetTFlags.py_type" + @@ -253,17 +270,32 @@ class PythonGenerator : public BaseGenerator { // Get the value of a fixed size array. void GetArrayOfStruct(const StructDef &struct_def, const FieldDef &field, - std::string *code_ptr) const { + std::string *code_ptr, ImportMap &imports) const { auto &code = *code_ptr; const auto vec_type = field.value.type.VectorType(); GenReceiver(struct_def, code_ptr); code += namer_.Method(field); - code += "(self, i: int):"; - if (parser_.opts.include_dependence_headers) { + + const ImportMapEntry import_entry = { + "." + GenPackageReference(field.value.type), TypeName(field) + }; + + if (parser_.opts.python_typing) { + const std::string return_type = ReturnType(struct_def, field); + code += "(self, i: int)"; + code += " -> " + return_type + ":"; + + imports.insert(import_entry); + } else { + code += "(self, i):"; + } + + if (parser_.opts.include_dependence_headers && !parser_.opts.python_typing) { code += GenIndents(2); - code += "from " + GenPackageReference(field.value.type) + " import " + - TypeName(field); + code += "from " + import_entry.first + " import " + import_entry.second + + "\n"; } + code += GenIndents(2) + "obj = " + TypeName(field) + "()"; code += GenIndents(2) + "obj.Init(self._tab.Bytes, self._tab.Pos + "; code += NumToString(field.value.offset) + " + i * "; @@ -299,11 +331,22 @@ class PythonGenerator : public BaseGenerator { // Get a struct by initializing an existing struct. // Specific to Table. void GetStructFieldOfTable(const StructDef &struct_def, const FieldDef &field, - std::string *code_ptr) const { + std::string *code_ptr, ImportMap &imports) const { auto &code = *code_ptr; GenReceiver(struct_def, code_ptr); - code += namer_.Method(field); - code += "(self):"; + code += namer_.Method(field) + "(self)"; + + const ImportMapEntry import_entry = { + "." + GenPackageReference(field.value.type), TypeName(field) + }; + + if (parser_.opts.python_typing) { + const std::string return_type = ReturnType(struct_def, field); + code += " -> Optional[" + return_type + "]"; + imports.insert(ImportMapEntry{ "typing", "Optional" }); + imports.insert(import_entry); + } + code += ":"; code += OffsetPrefix(field); if (field.value.type.struct_def->fixed) { code += Indent + Indent + Indent + "x = o + self._tab.Pos\n"; @@ -311,10 +354,11 @@ class PythonGenerator : public BaseGenerator { code += Indent + Indent + Indent; code += "x = self._tab.Indirect(o + self._tab.Pos)\n"; } - if (parser_.opts.include_dependence_headers) { + + if (parser_.opts.include_dependence_headers && !parser_.opts.python_typing) { code += Indent + Indent + Indent; - code += "from " + GenPackageReference(field.value.type) + " import " + - TypeName(field) + "\n"; + code += "from " + import_entry.first + " import " + import_entry.second + + "\n"; } code += Indent + Indent + Indent + "obj = " + TypeName(field) + "()\n"; code += Indent + Indent + Indent + "obj.Init(self._tab.Bytes, x)\n"; @@ -324,11 +368,18 @@ class PythonGenerator : public BaseGenerator { // Get the value of a string. void GetStringField(const StructDef &struct_def, const FieldDef &field, - std::string *code_ptr) const { + std::string *code_ptr, ImportMap &imports) const { auto &code = *code_ptr; GenReceiver(struct_def, code_ptr); code += namer_.Method(field); - code += "(self):"; + + if (parser_.opts.python_typing) { + code += "(self) -> Optional[str]:"; + imports.insert(ImportMapEntry{ "typing", "Optional" }); + } else { + code += "(self):"; + } + code += OffsetPrefix(field); code += Indent + Indent + Indent + "return " + GenGetter(field.value.type); code += "o + self._tab.Pos)\n"; @@ -337,21 +388,34 @@ class PythonGenerator : public BaseGenerator { // Get the value of a union from an object. void GetUnionField(const StructDef &struct_def, const FieldDef &field, - std::string *code_ptr) const { + std::string *code_ptr, ImportMap &imports) const { auto &code = *code_ptr; GenReceiver(struct_def, code_ptr); - code += namer_.Method(field) + "(self):"; - code += OffsetPrefix(field); + std::string return_ty = "flatbuffers.table.Table"; - // TODO(rw): this works and is not the good way to it: bool is_native_table = TypeName(field) == "*flatbuffers.Table"; + ImportMapEntry import_entry; if (is_native_table) { - code += - Indent + Indent + Indent + "from flatbuffers.table import Table\n"; - } else if (parser_.opts.include_dependence_headers) { + import_entry = ImportMapEntry{ "flatbuffers.table", "Table" }; + } else { + return_ty = TypeName(field); + import_entry = ImportMapEntry{ GenPackageReference(field.value.type), + TypeName(field) }; + } + + code += namer_.Method(field) + "(self)"; + if (parser_.opts.python_typing) { + code += " -> Optional[" + return_ty + "]"; + imports.insert(ImportMapEntry{ "typing", "Optional" }); + imports.insert(import_entry); + } + code += ":"; + code += OffsetPrefix(field); + + if (!parser_.opts.python_typing) { code += Indent + Indent + Indent; - code += "from " + GenPackageReference(field.value.type) + " import " + - TypeName(field) + "\n"; + code += "from " + import_entry.first + " import " + import_entry.second + + "\n"; } code += Indent + Indent + Indent + "obj = Table(bytearray(), 0)\n"; code += Indent + Indent + Indent + GenGetter(field.value.type); @@ -373,14 +437,26 @@ class PythonGenerator : public BaseGenerator { // Get the value of a vector's struct member. void GetMemberOfVectorOfStruct(const StructDef &struct_def, - const FieldDef &field, - std::string *code_ptr) const { + const FieldDef &field, std::string *code_ptr, + ImportMap &imports) const { auto &code = *code_ptr; auto vectortype = field.value.type.VectorType(); GenReceiver(struct_def, code_ptr); code += namer_.Method(field); - code += "(self, j):" + OffsetPrefix(field); + const ImportMapEntry import_entry = { + "." + GenPackageReference(field.value.type), TypeName(field) + }; + + if (parser_.opts.python_typing) { + const std::string return_type = ReturnType(struct_def, field); + code += "(self, j: int) -> Optional[" + return_type + "]"; + imports.insert(ImportMapEntry{ "typing", "Optional" }); + imports.insert(import_entry); + } else { + code += "(self, j)"; + } + code += ":" + OffsetPrefix(field); code += Indent + Indent + Indent + "x = self._tab.Vector(o)\n"; code += Indent + Indent + Indent; code += "x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * "; @@ -388,10 +464,10 @@ class PythonGenerator : public BaseGenerator { if (!(vectortype.struct_def->fixed)) { code += Indent + Indent + Indent + "x = self._tab.Indirect(x)\n"; } - if (parser_.opts.include_dependence_headers) { + if (parser_.opts.include_dependence_headers && !parser_.opts.python_typing) { code += Indent + Indent + Indent; - code += "from " + GenPackageReference(field.value.type) + " import " + - TypeName(field) + "\n"; + code += "from " + import_entry.first + " import " + import_entry.second + + "\n"; } code += Indent + Indent + Indent + "obj = " + TypeName(field) + "()\n"; code += Indent + Indent + Indent + "obj.Init(self._tab.Bytes, x)\n"; @@ -409,7 +485,12 @@ class PythonGenerator : public BaseGenerator { GenReceiver(struct_def, code_ptr); code += namer_.Method(field); - code += "(self, j):"; + if (parser_.opts.python_typing) { + code += "(self, j: int)"; + } else { + code += "(self, j)"; + } + code += ":"; code += OffsetPrefix(field); code += Indent + Indent + Indent + "a = self._tab.Vector(o)\n"; code += Indent + Indent + Indent; @@ -476,8 +557,8 @@ class PythonGenerator : public BaseGenerator { // Returns a nested flatbuffer as itself. void GetVectorAsNestedFlatbuffer(const StructDef &struct_def, - const FieldDef &field, - std::string *code_ptr) const { + const FieldDef &field, std::string *code_ptr, + ImportMap &imports) const { auto nested = field.attributes.Lookup("nested_flatbuffer"); if (!nested) { return; } // There is no nested flatbuffer. @@ -487,14 +568,26 @@ class PythonGenerator : public BaseGenerator { qualified_name = nested->constant; } + const ImportMapEntry import_entry = { "." + qualified_name, + unqualified_name }; + auto &code = *code_ptr; GenReceiver(struct_def, code_ptr); - code += namer_.Method(field) + "NestedRoot(self):"; + code += namer_.Method(field) + "NestedRoot(self)"; + if (parser_.opts.python_typing) { + code += " -> Union[" + unqualified_name + ", int]"; + imports.insert(ImportMapEntry{ "typing", "Union" }); + imports.insert(import_entry); + } + code += ":"; code += OffsetPrefix(field); - code += Indent + Indent + Indent; - code += "from " + qualified_name + " import " + unqualified_name + "\n"; + if (!parser_.opts.python_typing) { + code += Indent + Indent + Indent; + code += "from " + import_entry.first + " import " + import_entry.second + + "\n"; + } code += Indent + Indent + Indent + "return " + unqualified_name; code += ".GetRootAs"; code += "(self._tab.Bytes, self._tab.Vector(o))\n"; @@ -613,15 +706,25 @@ class PythonGenerator : public BaseGenerator { const auto name = parser_.opts.python_no_type_prefix_suffix ? "Start" : struct_type + "Start"; - code += "def " + name + "(builder):\n"; - code += Indent + "return builder.StartObject("; + code += "def " + name; + if (parser_.opts.python_typing) { + code += "(builder: flatbuffers.Builder):\n"; + } else { + code += "(builder):\n"; + } + + code += Indent + "builder.StartObject("; code += NumToString(struct_def.fields.vec.size()); code += ")\n\n"; if (!parser_.opts.one_file && !parser_.opts.python_no_type_prefix_suffix) { // Generate method without struct name. - code += "def Start(builder):\n"; - code += Indent + "return " + struct_type + "Start(builder)\n\n"; + if (parser_.opts.python_typing) { + code += "def Start(builder: flatbuffers.Builder):\n"; + } else { + code += "def Start(builder):\n"; + } + code += Indent + struct_type + "Start(builder)\n\n"; } } @@ -631,15 +734,19 @@ class PythonGenerator : public BaseGenerator { auto &code = *code_ptr; const std::string field_var = namer_.Variable(field); const std::string field_method = namer_.Method(field); + const std::string field_ty = GenFieldTy(field); const auto name = parser_.opts.python_no_type_prefix_suffix ? "Add" + field_method : namer_.Type(struct_def) + "Add" + field_method; // Generate method with struct name. code += "def " + name; - code += "(builder, "; - code += field_var; + if (parser_.opts.python_typing) { + code += "(builder: flatbuffers.Builder, " + field_var + ": " + field_ty; + } else { + code += "(builder, " + field_var; + } code += "):\n"; - code += Indent + "return builder.Prepend"; + code += Indent + "builder.Prepend"; code += GenMethod(field) + "Slot("; code += NumToString(offset) + ", "; if (!IsScalar(field.value.type.base_type) && (!struct_def.fixed)) { @@ -660,9 +767,9 @@ class PythonGenerator : public BaseGenerator { if (!parser_.opts.one_file && !parser_.opts.python_no_type_prefix_suffix) { // Generate method without struct name. - code += "def Add" + field_method + "(builder, " + field_var + "):\n"; + code += "def Add" + field_method + "(builder: flatbuffers.Builder, " + field_var + ": " + field_ty + "):\n"; code += - Indent + "return " + namer_.Type(struct_def) + "Add" + field_method; + Indent + namer_.Type(struct_def) + "Add" + field_method; code += "(builder, "; code += field_var; code += ")\n\n"; @@ -679,7 +786,12 @@ class PythonGenerator : public BaseGenerator { // Generate method with struct name. const auto name = parser_.opts.python_no_type_prefix_suffix ? "Start" + field_method : struct_type + "Start" + field_method; code += "def " + name; - code += "Vector(builder, numElems):\n"; + if (parser_.opts.python_typing) { + code += "Vector(builder, numElems: int) -> int:\n"; + } else { + code += "Vector(builder, numElems):\n"; + } + code += Indent + "return builder.StartVector("; auto vector_type = field.value.type.VectorType(); auto alignment = InlineAlignment(vector_type); @@ -690,7 +802,7 @@ class PythonGenerator : public BaseGenerator { if (!parser_.opts.one_file && !parser_.opts.python_no_type_prefix_suffix) { // Generate method without struct name. - code += "def Start" + field_method + "Vector(builder, numElems):\n"; + code += "def Start" + field_method + "Vector(builder, numElems: int) -> int:\n"; code += Indent + "return " + struct_type + "Start"; code += field_method + "Vector(builder, numElems)\n\n"; } @@ -739,12 +851,20 @@ class PythonGenerator : public BaseGenerator { const auto name = parser_.opts.python_no_type_prefix_suffix ? "End" : namer_.Type(struct_def) + "End"; // Generate method with struct name. - code += "def " + name + "(builder):\n"; + if (parser_.opts.python_typing) { + code += "def " + name + "(builder: flatbuffers.Builder) -> int:\n"; + } else { + code += "def " + name + "(builder):\n"; + } code += Indent + "return builder.EndObject()\n\n"; if (!parser_.opts.one_file && !parser_.opts.python_no_type_prefix_suffix) { // Generate method without struct name. - code += "def End(builder):\n"; + if (parser_.opts.python_typing) { + code += "def End(builder: flatbuffers.Builder) -> int:\n"; + } else { + code += "def End(builder):\n"; + } code += Indent + "return " + namer_.Type(struct_def) + "End(builder)"; code += "\n"; } @@ -759,7 +879,7 @@ class PythonGenerator : public BaseGenerator { // Generate a struct field, conditioned on its child type(s). void GenStructAccessor(const StructDef &struct_def, const FieldDef &field, - std::string *code_ptr) const { + std::string *code_ptr, ImportMap &imports) const { GenComment(field.doc_comment, code_ptr, &def_comment, Indent.c_str()); if (IsScalar(field.value.type.base_type)) { if (struct_def.fixed) { @@ -773,35 +893,35 @@ class PythonGenerator : public BaseGenerator { if (struct_def.fixed) { GetStructFieldOfStruct(struct_def, field, code_ptr); } else { - GetStructFieldOfTable(struct_def, field, code_ptr); + GetStructFieldOfTable(struct_def, field, code_ptr, imports); } break; case BASE_TYPE_STRING: - GetStringField(struct_def, field, code_ptr); + GetStringField(struct_def, field, code_ptr, imports); break; case BASE_TYPE_VECTOR: { auto vectortype = field.value.type.VectorType(); if (vectortype.base_type == BASE_TYPE_STRUCT) { - GetMemberOfVectorOfStruct(struct_def, field, code_ptr); + GetMemberOfVectorOfStruct(struct_def, field, code_ptr, imports); } else { GetMemberOfVectorOfNonStruct(struct_def, field, code_ptr); GetVectorOfNonStructAsNumpy(struct_def, field, code_ptr); - GetVectorAsNestedFlatbuffer(struct_def, field, code_ptr); + GetVectorAsNestedFlatbuffer(struct_def, field, code_ptr, imports); } break; } case BASE_TYPE_ARRAY: { auto vectortype = field.value.type.VectorType(); if (vectortype.base_type == BASE_TYPE_STRUCT) { - GetArrayOfStruct(struct_def, field, code_ptr); + GetArrayOfStruct(struct_def, field, code_ptr, imports); } else { GetArrayOfNonStruct(struct_def, field, code_ptr); GetVectorOfNonStructAsNumpy(struct_def, field, code_ptr); - GetVectorAsNestedFlatbuffer(struct_def, field, code_ptr); + GetVectorAsNestedFlatbuffer(struct_def, field, code_ptr, imports); } break; } - case BASE_TYPE_UNION: GetUnionField(struct_def, field, code_ptr); break; + case BASE_TYPE_UNION: GetUnionField(struct_def, field, code_ptr, imports); break; default: FLATBUFFERS_ASSERT(0); } } @@ -816,7 +936,11 @@ class PythonGenerator : public BaseGenerator { std::string *code_ptr) const { auto &code = *code_ptr; code += Indent + "@classmethod\n"; - code += Indent + "def SizeOf(cls):\n"; + if (parser_.opts.python_typing) { + code += Indent + "def SizeOf(cls) -> int:\n"; + } else { + code += Indent + "def SizeOf(cls):\n"; + } code += Indent + Indent + "return " + NumToString(struct_def.bytesize) + "\n"; code += "\n"; @@ -868,7 +992,8 @@ class PythonGenerator : public BaseGenerator { } // Generates struct or table methods. - void GenStruct(const StructDef &struct_def, std::string *code_ptr) const { + void GenStruct(const StructDef &struct_def, std::string *code_ptr, + ImportMap &imports) const { if (struct_def.generated) return; GenComment(struct_def.doc_comment, code_ptr, &def_comment); @@ -893,7 +1018,7 @@ class PythonGenerator : public BaseGenerator { auto &field = **it; if (field.deprecated) continue; - GenStructAccessor(struct_def, field, code_ptr); + GenStructAccessor(struct_def, field, code_ptr, imports); } if (struct_def.fixed) { @@ -1763,6 +1888,31 @@ class PythonGenerator : public BaseGenerator { } } + std::string GenFieldTy(const FieldDef &field) const { + if (IsScalar(field.value.type.base_type) || IsArray(field.value.type)) { + const std::string ty = GenTypeBasic(field.value.type); + if (ty.find("int") != std::string::npos) { + return "int"; + } + + if (ty.find("float") != std::string::npos) { + return "float"; + } + + if (ty == "bool") { + return "bool"; + } + + return "Any"; + } else { + if (IsStruct(field.value.type)) { + return "Any"; + } else { + return "int"; + } + } + } + // Returns the method name for use with add/put calls. std::string GenMethod(const FieldDef &field) const { return (IsScalar(field.value.type.base_type) || IsArray(field.value.type)) @@ -1805,6 +1955,31 @@ class PythonGenerator : public BaseGenerator { return GenTypeGet(field.value.type); } + std::string ReturnType(const StructDef &struct_def, + const FieldDef &field) const { + // If we have a class member that returns an instance of the same class, + // for example: + // class Field(object): + // def Children(self, j: int) -> Optional[Field]: + // pass + // + // we need to quote the return type: + // class Field(object): + // def Children(self, j: int) -> Optional['Field']: + // pass + // + // because Python is unable to resolve the name during parse and will return + // an error. + // (see PEP 484 under forward references: + // https://peps.python.org/pep-0484/#forward-references) + const std::string self_type = struct_def.name; + std::string field_type = TypeName(field); + + if (self_type == field_type) { field_type = "'" + field_type + "'"; } + + return field_type; + } + // Create a struct with a builder and the struct's arguments. void GenStructBuilder(const StructDef &struct_def, std::string *code_ptr) const { @@ -1822,13 +1997,16 @@ class PythonGenerator : public BaseGenerator { bool generate() { std::string one_file_code; + ImportMap one_file_imports; if (!generateEnums(&one_file_code)) return false; - if (!generateStructs(&one_file_code)) return false; + if (!generateStructs(&one_file_code, one_file_imports)) return false; if (parser_.opts.one_file) { + const std::string mod = file_name_ + "_generated"; + // Legacy file format uses keep casing. - return SaveType(file_name_ + "_generated.py", *parser_.current_namespace_, - one_file_code, true); + return SaveType(mod + ".py", *parser_.current_namespace_, one_file_code, + one_file_imports, mod, true); } return true; @@ -1848,29 +2026,45 @@ class PythonGenerator : public BaseGenerator { if (parser_.opts.one_file && !enumcode.empty()) { *one_file_code += enumcode + "\n\n"; } else { + ImportMap imports; + const std::string mod = + namer_.File(enum_def, SkipFile::SuffixAndExtension); + if (!SaveType(namer_.File(enum_def, SkipFile::Suffix), - *enum_def.defined_namespace, enumcode, false)) + *enum_def.defined_namespace, enumcode, imports, mod, + false)) return false; } } return true; } - bool generateStructs(std::string *one_file_code) const { + bool generateStructs(std::string *one_file_code, + ImportMap &one_file_imports) const { for (auto it = parser_.structs_.vec.begin(); it != parser_.structs_.vec.end(); ++it) { auto &struct_def = **it; std::string declcode; - GenStruct(struct_def, &declcode); + ImportMap imports; + GenStruct(struct_def, &declcode, imports); if (parser_.opts.generate_object_based_api) { GenStructForObjectAPI(struct_def, &declcode); } - if (parser_.opts.one_file && !declcode.empty()) { - *one_file_code += declcode + "\n\n"; + if (parser_.opts.one_file) { + if (!declcode.empty()) { + *one_file_code += declcode + "\n\n"; + } + + for (auto import_str: imports) { + one_file_imports.insert(import_str); + } } else { + const std::string mod = + namer_.File(struct_def, SkipFile::SuffixAndExtension); if (!SaveType(namer_.File(struct_def, SkipFile::Suffix), - *struct_def.defined_namespace, declcode, true)) + *struct_def.defined_namespace, declcode, imports, mod, + true)) return false; } } @@ -1879,24 +2073,44 @@ class PythonGenerator : public BaseGenerator { // Begin by declaring namespace and imports. void BeginFile(const std::string &name_space_name, const bool needs_imports, - std::string *code_ptr) const { + std::string *code_ptr, const std::string &mod, + const ImportMap &imports) const { auto &code = *code_ptr; code = code + "# " + FlatBuffersGeneratedWarning() + "\n\n"; code += "# namespace: " + name_space_name + "\n\n"; + if (needs_imports) { + const std::string local_import = "." + mod; + code += "import flatbuffers\n"; code += "from flatbuffers.compat import import_numpy\n"; + if (parser_.opts.python_typing) { + code += "from typing import Any\n"; + + for (auto import_entry : imports) { + // If we have a file called, say, "MyType.py" and in it we have a + // class "MyType", we can generate imports -- usually when we + // have a type that contains arrays of itself -- of the type + // "from .MyType import MyType", which Python can't resolve. So + // if we are trying to import ourself, we skip. + if (import_entry.first != local_import) { + code += "from " + import_entry.first + " import " + + import_entry.second + "\n"; + } + } + } code += "np = import_numpy()\n\n"; } } // Save out the generated code for a Python Table type. bool SaveType(const std::string &defname, const Namespace &ns, - const std::string &classcode, bool needs_imports) const { + const std::string &classcode, const ImportMap &imports, + const std::string &mod, bool needs_imports) const { if (!classcode.length()) return true; std::string code = ""; - BeginFile(LastNamespacePart(ns), needs_imports, &code); + BeginFile(LastNamespacePart(ns), needs_imports, &code, mod, imports); code += classcode; const std::string directories = diff --git a/tests/MyGame/Example/ArrayStruct.py b/tests/MyGame/Example/ArrayStruct.py index d80f8425..be85ec89 100644 --- a/tests/MyGame/Example/ArrayStruct.py +++ b/tests/MyGame/Example/ArrayStruct.py @@ -4,17 +4,19 @@ import flatbuffers from flatbuffers.compat import import_numpy +from typing import Any +from .MyGame.Example.NestedStruct import NestedStruct np = import_numpy() class ArrayStruct(object): __slots__ = ['_tab'] @classmethod - def SizeOf(cls): + def SizeOf(cls) -> int: return 160 # ArrayStruct - def Init(self, buf, pos): + def Init(self, buf: bytes, pos: int): self._tab = flatbuffers.table.Table(buf, pos) # ArrayStruct @@ -33,28 +35,27 @@ class ArrayStruct(object): return self._tab.GetArrayAsNumpy(flatbuffers.number_types.Int32Flags, self._tab.Pos + 4, self.BLength()) # ArrayStruct - def BLength(self): + def BLength(self) -> int: return 15 # ArrayStruct - def BIsNone(self): + def BIsNone(self) -> bool: return False # ArrayStruct def C(self): return self._tab.Get(flatbuffers.number_types.Int8Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(64)) # ArrayStruct - def D(self, i: int): - from MyGame.Example.NestedStruct import NestedStruct + def D(self, i: int) -> NestedStruct: obj = NestedStruct() obj.Init(self._tab.Bytes, self._tab.Pos + 72 + i * 32) return obj # ArrayStruct - def DLength(self): + def DLength(self) -> int: return 2 # ArrayStruct - def DIsNone(self): + def DIsNone(self) -> bool: return False # ArrayStruct @@ -73,11 +74,11 @@ class ArrayStruct(object): return self._tab.GetArrayAsNumpy(flatbuffers.number_types.Int64Flags, self._tab.Pos + 144, self.FLength()) # ArrayStruct - def FLength(self): + def FLength(self) -> int: return 2 # ArrayStruct - def FIsNone(self): + def FIsNone(self) -> bool: return False diff --git a/tests/MyGame/Example/ArrayTable.py b/tests/MyGame/Example/ArrayTable.py index 7f4051f5..90fbb4a4 100644 --- a/tests/MyGame/Example/ArrayTable.py +++ b/tests/MyGame/Example/ArrayTable.py @@ -4,13 +4,16 @@ import flatbuffers from flatbuffers.compat import import_numpy +from typing import Any +from .MyGame.Example.ArrayStruct import ArrayStruct +from typing import Optional np = import_numpy() class ArrayTable(object): __slots__ = ['_tab'] @classmethod - def GetRootAs(cls, buf, offset=0): + def GetRootAs(cls, buf, offset: int = 0): n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) x = ArrayTable() x.Init(buf, n + offset) @@ -25,36 +28,35 @@ class ArrayTable(object): return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x41\x52\x52\x54", size_prefixed=size_prefixed) # ArrayTable - def Init(self, buf, pos): + def Init(self, buf: bytes, pos: int): self._tab = flatbuffers.table.Table(buf, pos) # ArrayTable - def A(self): + def A(self) -> Optional[ArrayStruct]: o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) if o != 0: x = o + self._tab.Pos - from MyGame.Example.ArrayStruct import ArrayStruct obj = ArrayStruct() obj.Init(self._tab.Bytes, x) return obj return None -def ArrayTableStart(builder): - return builder.StartObject(1) +def ArrayTableStart(builder: flatbuffers.Builder): + builder.StartObject(1) -def Start(builder): - return ArrayTableStart(builder) +def Start(builder: flatbuffers.Builder): + ArrayTableStart(builder) -def ArrayTableAddA(builder, a): - return builder.PrependStructSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(a), 0) +def ArrayTableAddA(builder: flatbuffers.Builder, a: Any): + builder.PrependStructSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(a), 0) -def AddA(builder, a): - return ArrayTableAddA(builder, a) +def AddA(builder: flatbuffers.Builder, a: Any): + ArrayTableAddA(builder, a) -def ArrayTableEnd(builder): +def ArrayTableEnd(builder: flatbuffers.Builder) -> int: return builder.EndObject() -def End(builder): +def End(builder: flatbuffers.Builder) -> int: return ArrayTableEnd(builder) import MyGame.Example.ArrayStruct diff --git a/tests/MyGame/Example/Monster.py b/tests/MyGame/Example/Monster.py index bde02b4a..f216f84f 100644 --- a/tests/MyGame/Example/Monster.py +++ b/tests/MyGame/Example/Monster.py @@ -34,7 +34,7 @@ class Monster(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) if o != 0: x = o + self._tab.Pos - from MyGame.Example.Vec3 import Vec3 + from .MyGame.Example.Vec3 import Vec3 obj = Vec3() obj.Init(self._tab.Bytes, x) return obj @@ -118,7 +118,7 @@ class Monster(object): if o != 0: x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 - from MyGame.Example.Test import Test + from .MyGame.Example.Test import Test obj = Test() obj.Init(self._tab.Bytes, x) return obj @@ -165,7 +165,7 @@ class Monster(object): x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 x = self._tab.Indirect(x) - from MyGame.Example.Monster import Monster + from .MyGame.Example.Monster import Monster obj = Monster() obj.Init(self._tab.Bytes, x) return obj @@ -188,7 +188,7 @@ class Monster(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(28)) if o != 0: x = self._tab.Indirect(o + self._tab.Pos) - from MyGame.Example.Monster import Monster + from .MyGame.Example.Monster import Monster obj = Monster() obj.Init(self._tab.Bytes, x) return obj @@ -213,7 +213,7 @@ class Monster(object): def TestnestedflatbufferNestedRoot(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(30)) if o != 0: - from MyGame.Example.Monster import Monster + from .MyGame.Example.Monster import Monster return Monster.GetRootAs(self._tab.Bytes, self._tab.Vector(o)) return 0 @@ -234,7 +234,7 @@ class Monster(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(32)) if o != 0: x = self._tab.Indirect(o + self._tab.Pos) - from MyGame.Example.Stat import Stat + from .MyGame.Example.Stat import Stat obj = Stat() obj.Init(self._tab.Bytes, x) return obj @@ -377,7 +377,7 @@ class Monster(object): if o != 0: x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 8 - from MyGame.Example.Ability import Ability + from .MyGame.Example.Ability import Ability obj = Ability() obj.Init(self._tab.Bytes, x) return obj @@ -428,7 +428,7 @@ class Monster(object): if o != 0: x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 - from MyGame.Example.Test import Test + from .MyGame.Example.Test import Test obj = Test() obj.Init(self._tab.Bytes, x) return obj @@ -505,7 +505,7 @@ class Monster(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(72)) if o != 0: x = self._tab.Indirect(o + self._tab.Pos) - from MyGame.InParentNamespace import InParentNamespace + from .MyGame.InParentNamespace import InParentNamespace obj = InParentNamespace() obj.Init(self._tab.Bytes, x) return obj @@ -518,7 +518,7 @@ class Monster(object): x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 x = self._tab.Indirect(x) - from MyGame.Example.Referrable import Referrable + from .MyGame.Example.Referrable import Referrable obj = Referrable() obj.Init(self._tab.Bytes, x) return obj @@ -577,7 +577,7 @@ class Monster(object): x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 x = self._tab.Indirect(x) - from MyGame.Example.Referrable import Referrable + from .MyGame.Example.Referrable import Referrable obj = Referrable() obj.Init(self._tab.Bytes, x) return obj @@ -750,7 +750,7 @@ class Monster(object): def TestrequirednestedflatbufferNestedRoot(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(102)) if o != 0: - from MyGame.Example.Monster import Monster + from .MyGame.Example.Monster import Monster return Monster.GetRootAs(self._tab.Bytes, self._tab.Vector(o)) return 0 @@ -773,7 +773,7 @@ class Monster(object): x = self._tab.Vector(o) x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 x = self._tab.Indirect(x) - from MyGame.Example.Stat import Stat + from .MyGame.Example.Stat import Stat obj = Stat() obj.Init(self._tab.Bytes, x) return obj @@ -796,7 +796,7 @@ class Monster(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(106)) if o != 0: x = o + self._tab.Pos - from MyGame.Example.Test import Test + from .MyGame.Example.Test import Test obj = Test() obj.Init(self._tab.Bytes, x) return obj @@ -873,117 +873,117 @@ class Monster(object): return float('inf') def MonsterStart(builder): - return builder.StartObject(62) + builder.StartObject(62) def Start(builder): - return MonsterStart(builder) + MonsterStart(builder) def MonsterAddPos(builder, pos): - return builder.PrependStructSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(pos), 0) + builder.PrependStructSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(pos), 0) -def AddPos(builder, pos): - return MonsterAddPos(builder, pos) +def AddPos(builder: flatbuffers.Builder, pos: Any): + MonsterAddPos(builder, pos) def MonsterAddMana(builder, mana): - return builder.PrependInt16Slot(1, mana, 150) + builder.PrependInt16Slot(1, mana, 150) -def AddMana(builder, mana): - return MonsterAddMana(builder, mana) +def AddMana(builder: flatbuffers.Builder, mana: int): + MonsterAddMana(builder, mana) def MonsterAddHp(builder, hp): - return builder.PrependInt16Slot(2, hp, 100) + builder.PrependInt16Slot(2, hp, 100) -def AddHp(builder, hp): - return MonsterAddHp(builder, hp) +def AddHp(builder: flatbuffers.Builder, hp: int): + MonsterAddHp(builder, hp) def MonsterAddName(builder, name): - return builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) -def AddName(builder, name): - return MonsterAddName(builder, name) +def AddName(builder: flatbuffers.Builder, name: int): + MonsterAddName(builder, name) def MonsterAddInventory(builder, inventory): - return builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(inventory), 0) + builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(inventory), 0) -def AddInventory(builder, inventory): - return MonsterAddInventory(builder, inventory) +def AddInventory(builder: flatbuffers.Builder, inventory: int): + MonsterAddInventory(builder, inventory) def MonsterStartInventoryVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def StartInventoryVector(builder, numElems): +def StartInventoryVector(builder, numElems: int) -> int: return MonsterStartInventoryVector(builder, numElems) def MonsterAddColor(builder, color): - return builder.PrependUint8Slot(6, color, 8) + builder.PrependUint8Slot(6, color, 8) -def AddColor(builder, color): - return MonsterAddColor(builder, color) +def AddColor(builder: flatbuffers.Builder, color: int): + MonsterAddColor(builder, color) def MonsterAddTestType(builder, testType): - return builder.PrependUint8Slot(7, testType, 0) + builder.PrependUint8Slot(7, testType, 0) -def AddTestType(builder, testType): - return MonsterAddTestType(builder, testType) +def AddTestType(builder: flatbuffers.Builder, testType: int): + MonsterAddTestType(builder, testType) def MonsterAddTest(builder, test): - return builder.PrependUOffsetTRelativeSlot(8, flatbuffers.number_types.UOffsetTFlags.py_type(test), 0) + builder.PrependUOffsetTRelativeSlot(8, flatbuffers.number_types.UOffsetTFlags.py_type(test), 0) -def AddTest(builder, test): - return MonsterAddTest(builder, test) +def AddTest(builder: flatbuffers.Builder, test: int): + MonsterAddTest(builder, test) def MonsterAddTest4(builder, test4): - return builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(test4), 0) + builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(test4), 0) -def AddTest4(builder, test4): - return MonsterAddTest4(builder, test4) +def AddTest4(builder: flatbuffers.Builder, test4: int): + MonsterAddTest4(builder, test4) def MonsterStartTest4Vector(builder, numElems): return builder.StartVector(4, numElems, 2) -def StartTest4Vector(builder, numElems): +def StartTest4Vector(builder, numElems: int) -> int: return MonsterStartTest4Vector(builder, numElems) def MonsterAddTestarrayofstring(builder, testarrayofstring): - return builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofstring), 0) + builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofstring), 0) -def AddTestarrayofstring(builder, testarrayofstring): - return MonsterAddTestarrayofstring(builder, testarrayofstring) +def AddTestarrayofstring(builder: flatbuffers.Builder, testarrayofstring: int): + MonsterAddTestarrayofstring(builder, testarrayofstring) def MonsterStartTestarrayofstringVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartTestarrayofstringVector(builder, numElems): +def StartTestarrayofstringVector(builder, numElems: int) -> int: return MonsterStartTestarrayofstringVector(builder, numElems) def MonsterAddTestarrayoftables(builder, testarrayoftables): - return builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayoftables), 0) + builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayoftables), 0) -def AddTestarrayoftables(builder, testarrayoftables): - return MonsterAddTestarrayoftables(builder, testarrayoftables) +def AddTestarrayoftables(builder: flatbuffers.Builder, testarrayoftables: int): + MonsterAddTestarrayoftables(builder, testarrayoftables) def MonsterStartTestarrayoftablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartTestarrayoftablesVector(builder, numElems): +def StartTestarrayoftablesVector(builder, numElems: int) -> int: return MonsterStartTestarrayoftablesVector(builder, numElems) def MonsterAddEnemy(builder, enemy): - return builder.PrependUOffsetTRelativeSlot(12, flatbuffers.number_types.UOffsetTFlags.py_type(enemy), 0) + builder.PrependUOffsetTRelativeSlot(12, flatbuffers.number_types.UOffsetTFlags.py_type(enemy), 0) -def AddEnemy(builder, enemy): - return MonsterAddEnemy(builder, enemy) +def AddEnemy(builder: flatbuffers.Builder, enemy: int): + MonsterAddEnemy(builder, enemy) def MonsterAddTestnestedflatbuffer(builder, testnestedflatbuffer): - return builder.PrependUOffsetTRelativeSlot(13, flatbuffers.number_types.UOffsetTFlags.py_type(testnestedflatbuffer), 0) + builder.PrependUOffsetTRelativeSlot(13, flatbuffers.number_types.UOffsetTFlags.py_type(testnestedflatbuffer), 0) -def AddTestnestedflatbuffer(builder, testnestedflatbuffer): - return MonsterAddTestnestedflatbuffer(builder, testnestedflatbuffer) +def AddTestnestedflatbuffer(builder: flatbuffers.Builder, testnestedflatbuffer: int): + MonsterAddTestnestedflatbuffer(builder, testnestedflatbuffer) def MonsterStartTestnestedflatbufferVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def StartTestnestedflatbufferVector(builder, numElems): +def StartTestnestedflatbufferVector(builder, numElems: int) -> int: return MonsterStartTestnestedflatbufferVector(builder, numElems) def MonsterMakeTestnestedflatbufferVectorFromBytes(builder, bytes): @@ -994,303 +994,303 @@ def MonsterMakeTestnestedflatbufferVectorFromBytes(builder, bytes): def MakeTestnestedflatbufferVectorFromBytes(builder, bytes): return MonsterMakeTestnestedflatbufferVectorFromBytes(builder, bytes) def MonsterAddTestempty(builder, testempty): - return builder.PrependUOffsetTRelativeSlot(14, flatbuffers.number_types.UOffsetTFlags.py_type(testempty), 0) + builder.PrependUOffsetTRelativeSlot(14, flatbuffers.number_types.UOffsetTFlags.py_type(testempty), 0) -def AddTestempty(builder, testempty): - return MonsterAddTestempty(builder, testempty) +def AddTestempty(builder: flatbuffers.Builder, testempty: int): + MonsterAddTestempty(builder, testempty) def MonsterAddTestbool(builder, testbool): - return builder.PrependBoolSlot(15, testbool, 0) + builder.PrependBoolSlot(15, testbool, 0) -def AddTestbool(builder, testbool): - return MonsterAddTestbool(builder, testbool) +def AddTestbool(builder: flatbuffers.Builder, testbool: bool): + MonsterAddTestbool(builder, testbool) def MonsterAddTesthashs32Fnv1(builder, testhashs32Fnv1): - return builder.PrependInt32Slot(16, testhashs32Fnv1, 0) + builder.PrependInt32Slot(16, testhashs32Fnv1, 0) -def AddTesthashs32Fnv1(builder, testhashs32Fnv1): - return MonsterAddTesthashs32Fnv1(builder, testhashs32Fnv1) +def AddTesthashs32Fnv1(builder: flatbuffers.Builder, testhashs32Fnv1: int): + MonsterAddTesthashs32Fnv1(builder, testhashs32Fnv1) def MonsterAddTesthashu32Fnv1(builder, testhashu32Fnv1): - return builder.PrependUint32Slot(17, testhashu32Fnv1, 0) + builder.PrependUint32Slot(17, testhashu32Fnv1, 0) -def AddTesthashu32Fnv1(builder, testhashu32Fnv1): - return MonsterAddTesthashu32Fnv1(builder, testhashu32Fnv1) +def AddTesthashu32Fnv1(builder: flatbuffers.Builder, testhashu32Fnv1: int): + MonsterAddTesthashu32Fnv1(builder, testhashu32Fnv1) def MonsterAddTesthashs64Fnv1(builder, testhashs64Fnv1): - return builder.PrependInt64Slot(18, testhashs64Fnv1, 0) + builder.PrependInt64Slot(18, testhashs64Fnv1, 0) -def AddTesthashs64Fnv1(builder, testhashs64Fnv1): - return MonsterAddTesthashs64Fnv1(builder, testhashs64Fnv1) +def AddTesthashs64Fnv1(builder: flatbuffers.Builder, testhashs64Fnv1: int): + MonsterAddTesthashs64Fnv1(builder, testhashs64Fnv1) def MonsterAddTesthashu64Fnv1(builder, testhashu64Fnv1): - return builder.PrependUint64Slot(19, testhashu64Fnv1, 0) + builder.PrependUint64Slot(19, testhashu64Fnv1, 0) -def AddTesthashu64Fnv1(builder, testhashu64Fnv1): - return MonsterAddTesthashu64Fnv1(builder, testhashu64Fnv1) +def AddTesthashu64Fnv1(builder: flatbuffers.Builder, testhashu64Fnv1: int): + MonsterAddTesthashu64Fnv1(builder, testhashu64Fnv1) def MonsterAddTesthashs32Fnv1a(builder, testhashs32Fnv1a): - return builder.PrependInt32Slot(20, testhashs32Fnv1a, 0) + builder.PrependInt32Slot(20, testhashs32Fnv1a, 0) -def AddTesthashs32Fnv1a(builder, testhashs32Fnv1a): - return MonsterAddTesthashs32Fnv1a(builder, testhashs32Fnv1a) +def AddTesthashs32Fnv1a(builder: flatbuffers.Builder, testhashs32Fnv1a: int): + MonsterAddTesthashs32Fnv1a(builder, testhashs32Fnv1a) def MonsterAddTesthashu32Fnv1a(builder, testhashu32Fnv1a): - return builder.PrependUint32Slot(21, testhashu32Fnv1a, 0) + builder.PrependUint32Slot(21, testhashu32Fnv1a, 0) -def AddTesthashu32Fnv1a(builder, testhashu32Fnv1a): - return MonsterAddTesthashu32Fnv1a(builder, testhashu32Fnv1a) +def AddTesthashu32Fnv1a(builder: flatbuffers.Builder, testhashu32Fnv1a: int): + MonsterAddTesthashu32Fnv1a(builder, testhashu32Fnv1a) def MonsterAddTesthashs64Fnv1a(builder, testhashs64Fnv1a): - return builder.PrependInt64Slot(22, testhashs64Fnv1a, 0) + builder.PrependInt64Slot(22, testhashs64Fnv1a, 0) -def AddTesthashs64Fnv1a(builder, testhashs64Fnv1a): - return MonsterAddTesthashs64Fnv1a(builder, testhashs64Fnv1a) +def AddTesthashs64Fnv1a(builder: flatbuffers.Builder, testhashs64Fnv1a: int): + MonsterAddTesthashs64Fnv1a(builder, testhashs64Fnv1a) def MonsterAddTesthashu64Fnv1a(builder, testhashu64Fnv1a): - return builder.PrependUint64Slot(23, testhashu64Fnv1a, 0) + builder.PrependUint64Slot(23, testhashu64Fnv1a, 0) -def AddTesthashu64Fnv1a(builder, testhashu64Fnv1a): - return MonsterAddTesthashu64Fnv1a(builder, testhashu64Fnv1a) +def AddTesthashu64Fnv1a(builder: flatbuffers.Builder, testhashu64Fnv1a: int): + MonsterAddTesthashu64Fnv1a(builder, testhashu64Fnv1a) def MonsterAddTestarrayofbools(builder, testarrayofbools): - return builder.PrependUOffsetTRelativeSlot(24, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofbools), 0) + builder.PrependUOffsetTRelativeSlot(24, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofbools), 0) -def AddTestarrayofbools(builder, testarrayofbools): - return MonsterAddTestarrayofbools(builder, testarrayofbools) +def AddTestarrayofbools(builder: flatbuffers.Builder, testarrayofbools: int): + MonsterAddTestarrayofbools(builder, testarrayofbools) def MonsterStartTestarrayofboolsVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def StartTestarrayofboolsVector(builder, numElems): +def StartTestarrayofboolsVector(builder, numElems: int) -> int: return MonsterStartTestarrayofboolsVector(builder, numElems) def MonsterAddTestf(builder, testf): - return builder.PrependFloat32Slot(25, testf, 3.14159) + builder.PrependFloat32Slot(25, testf, 3.14159) -def AddTestf(builder, testf): - return MonsterAddTestf(builder, testf) +def AddTestf(builder: flatbuffers.Builder, testf: float): + MonsterAddTestf(builder, testf) def MonsterAddTestf2(builder, testf2): - return builder.PrependFloat32Slot(26, testf2, 3.0) + builder.PrependFloat32Slot(26, testf2, 3.0) -def AddTestf2(builder, testf2): - return MonsterAddTestf2(builder, testf2) +def AddTestf2(builder: flatbuffers.Builder, testf2: float): + MonsterAddTestf2(builder, testf2) def MonsterAddTestf3(builder, testf3): - return builder.PrependFloat32Slot(27, testf3, 0.0) + builder.PrependFloat32Slot(27, testf3, 0.0) -def AddTestf3(builder, testf3): - return MonsterAddTestf3(builder, testf3) +def AddTestf3(builder: flatbuffers.Builder, testf3: float): + MonsterAddTestf3(builder, testf3) def MonsterAddTestarrayofstring2(builder, testarrayofstring2): - return builder.PrependUOffsetTRelativeSlot(28, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofstring2), 0) + builder.PrependUOffsetTRelativeSlot(28, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofstring2), 0) -def AddTestarrayofstring2(builder, testarrayofstring2): - return MonsterAddTestarrayofstring2(builder, testarrayofstring2) +def AddTestarrayofstring2(builder: flatbuffers.Builder, testarrayofstring2: int): + MonsterAddTestarrayofstring2(builder, testarrayofstring2) def MonsterStartTestarrayofstring2Vector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartTestarrayofstring2Vector(builder, numElems): +def StartTestarrayofstring2Vector(builder, numElems: int) -> int: return MonsterStartTestarrayofstring2Vector(builder, numElems) def MonsterAddTestarrayofsortedstruct(builder, testarrayofsortedstruct): - return builder.PrependUOffsetTRelativeSlot(29, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofsortedstruct), 0) + builder.PrependUOffsetTRelativeSlot(29, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofsortedstruct), 0) -def AddTestarrayofsortedstruct(builder, testarrayofsortedstruct): - return MonsterAddTestarrayofsortedstruct(builder, testarrayofsortedstruct) +def AddTestarrayofsortedstruct(builder: flatbuffers.Builder, testarrayofsortedstruct: int): + MonsterAddTestarrayofsortedstruct(builder, testarrayofsortedstruct) def MonsterStartTestarrayofsortedstructVector(builder, numElems): return builder.StartVector(8, numElems, 4) -def StartTestarrayofsortedstructVector(builder, numElems): +def StartTestarrayofsortedstructVector(builder, numElems: int) -> int: return MonsterStartTestarrayofsortedstructVector(builder, numElems) def MonsterAddFlex(builder, flex): - return builder.PrependUOffsetTRelativeSlot(30, flatbuffers.number_types.UOffsetTFlags.py_type(flex), 0) + builder.PrependUOffsetTRelativeSlot(30, flatbuffers.number_types.UOffsetTFlags.py_type(flex), 0) -def AddFlex(builder, flex): - return MonsterAddFlex(builder, flex) +def AddFlex(builder: flatbuffers.Builder, flex: int): + MonsterAddFlex(builder, flex) def MonsterStartFlexVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def StartFlexVector(builder, numElems): +def StartFlexVector(builder, numElems: int) -> int: return MonsterStartFlexVector(builder, numElems) def MonsterAddTest5(builder, test5): - return builder.PrependUOffsetTRelativeSlot(31, flatbuffers.number_types.UOffsetTFlags.py_type(test5), 0) + builder.PrependUOffsetTRelativeSlot(31, flatbuffers.number_types.UOffsetTFlags.py_type(test5), 0) -def AddTest5(builder, test5): - return MonsterAddTest5(builder, test5) +def AddTest5(builder: flatbuffers.Builder, test5: int): + MonsterAddTest5(builder, test5) def MonsterStartTest5Vector(builder, numElems): return builder.StartVector(4, numElems, 2) -def StartTest5Vector(builder, numElems): +def StartTest5Vector(builder, numElems: int) -> int: return MonsterStartTest5Vector(builder, numElems) def MonsterAddVectorOfLongs(builder, vectorOfLongs): - return builder.PrependUOffsetTRelativeSlot(32, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfLongs), 0) + builder.PrependUOffsetTRelativeSlot(32, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfLongs), 0) -def AddVectorOfLongs(builder, vectorOfLongs): - return MonsterAddVectorOfLongs(builder, vectorOfLongs) +def AddVectorOfLongs(builder: flatbuffers.Builder, vectorOfLongs: int): + MonsterAddVectorOfLongs(builder, vectorOfLongs) def MonsterStartVectorOfLongsVector(builder, numElems): return builder.StartVector(8, numElems, 8) -def StartVectorOfLongsVector(builder, numElems): +def StartVectorOfLongsVector(builder, numElems: int) -> int: return MonsterStartVectorOfLongsVector(builder, numElems) def MonsterAddVectorOfDoubles(builder, vectorOfDoubles): - return builder.PrependUOffsetTRelativeSlot(33, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfDoubles), 0) + builder.PrependUOffsetTRelativeSlot(33, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfDoubles), 0) -def AddVectorOfDoubles(builder, vectorOfDoubles): - return MonsterAddVectorOfDoubles(builder, vectorOfDoubles) +def AddVectorOfDoubles(builder: flatbuffers.Builder, vectorOfDoubles: int): + MonsterAddVectorOfDoubles(builder, vectorOfDoubles) def MonsterStartVectorOfDoublesVector(builder, numElems): return builder.StartVector(8, numElems, 8) -def StartVectorOfDoublesVector(builder, numElems): +def StartVectorOfDoublesVector(builder, numElems: int) -> int: return MonsterStartVectorOfDoublesVector(builder, numElems) def MonsterAddParentNamespaceTest(builder, parentNamespaceTest): - return builder.PrependUOffsetTRelativeSlot(34, flatbuffers.number_types.UOffsetTFlags.py_type(parentNamespaceTest), 0) + builder.PrependUOffsetTRelativeSlot(34, flatbuffers.number_types.UOffsetTFlags.py_type(parentNamespaceTest), 0) -def AddParentNamespaceTest(builder, parentNamespaceTest): - return MonsterAddParentNamespaceTest(builder, parentNamespaceTest) +def AddParentNamespaceTest(builder: flatbuffers.Builder, parentNamespaceTest: int): + MonsterAddParentNamespaceTest(builder, parentNamespaceTest) def MonsterAddVectorOfReferrables(builder, vectorOfReferrables): - return builder.PrependUOffsetTRelativeSlot(35, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfReferrables), 0) + builder.PrependUOffsetTRelativeSlot(35, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfReferrables), 0) -def AddVectorOfReferrables(builder, vectorOfReferrables): - return MonsterAddVectorOfReferrables(builder, vectorOfReferrables) +def AddVectorOfReferrables(builder: flatbuffers.Builder, vectorOfReferrables: int): + MonsterAddVectorOfReferrables(builder, vectorOfReferrables) def MonsterStartVectorOfReferrablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartVectorOfReferrablesVector(builder, numElems): +def StartVectorOfReferrablesVector(builder, numElems: int) -> int: return MonsterStartVectorOfReferrablesVector(builder, numElems) def MonsterAddSingleWeakReference(builder, singleWeakReference): - return builder.PrependUint64Slot(36, singleWeakReference, 0) + builder.PrependUint64Slot(36, singleWeakReference, 0) -def AddSingleWeakReference(builder, singleWeakReference): - return MonsterAddSingleWeakReference(builder, singleWeakReference) +def AddSingleWeakReference(builder: flatbuffers.Builder, singleWeakReference: int): + MonsterAddSingleWeakReference(builder, singleWeakReference) def MonsterAddVectorOfWeakReferences(builder, vectorOfWeakReferences): - return builder.PrependUOffsetTRelativeSlot(37, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfWeakReferences), 0) + builder.PrependUOffsetTRelativeSlot(37, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfWeakReferences), 0) -def AddVectorOfWeakReferences(builder, vectorOfWeakReferences): - return MonsterAddVectorOfWeakReferences(builder, vectorOfWeakReferences) +def AddVectorOfWeakReferences(builder: flatbuffers.Builder, vectorOfWeakReferences: int): + MonsterAddVectorOfWeakReferences(builder, vectorOfWeakReferences) def MonsterStartVectorOfWeakReferencesVector(builder, numElems): return builder.StartVector(8, numElems, 8) -def StartVectorOfWeakReferencesVector(builder, numElems): +def StartVectorOfWeakReferencesVector(builder, numElems: int) -> int: return MonsterStartVectorOfWeakReferencesVector(builder, numElems) def MonsterAddVectorOfStrongReferrables(builder, vectorOfStrongReferrables): - return builder.PrependUOffsetTRelativeSlot(38, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfStrongReferrables), 0) + builder.PrependUOffsetTRelativeSlot(38, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfStrongReferrables), 0) -def AddVectorOfStrongReferrables(builder, vectorOfStrongReferrables): - return MonsterAddVectorOfStrongReferrables(builder, vectorOfStrongReferrables) +def AddVectorOfStrongReferrables(builder: flatbuffers.Builder, vectorOfStrongReferrables: int): + MonsterAddVectorOfStrongReferrables(builder, vectorOfStrongReferrables) def MonsterStartVectorOfStrongReferrablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartVectorOfStrongReferrablesVector(builder, numElems): +def StartVectorOfStrongReferrablesVector(builder, numElems: int) -> int: return MonsterStartVectorOfStrongReferrablesVector(builder, numElems) def MonsterAddCoOwningReference(builder, coOwningReference): - return builder.PrependUint64Slot(39, coOwningReference, 0) + builder.PrependUint64Slot(39, coOwningReference, 0) -def AddCoOwningReference(builder, coOwningReference): - return MonsterAddCoOwningReference(builder, coOwningReference) +def AddCoOwningReference(builder: flatbuffers.Builder, coOwningReference: int): + MonsterAddCoOwningReference(builder, coOwningReference) def MonsterAddVectorOfCoOwningReferences(builder, vectorOfCoOwningReferences): - return builder.PrependUOffsetTRelativeSlot(40, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfCoOwningReferences), 0) + builder.PrependUOffsetTRelativeSlot(40, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfCoOwningReferences), 0) -def AddVectorOfCoOwningReferences(builder, vectorOfCoOwningReferences): - return MonsterAddVectorOfCoOwningReferences(builder, vectorOfCoOwningReferences) +def AddVectorOfCoOwningReferences(builder: flatbuffers.Builder, vectorOfCoOwningReferences: int): + MonsterAddVectorOfCoOwningReferences(builder, vectorOfCoOwningReferences) def MonsterStartVectorOfCoOwningReferencesVector(builder, numElems): return builder.StartVector(8, numElems, 8) -def StartVectorOfCoOwningReferencesVector(builder, numElems): +def StartVectorOfCoOwningReferencesVector(builder, numElems: int) -> int: return MonsterStartVectorOfCoOwningReferencesVector(builder, numElems) def MonsterAddNonOwningReference(builder, nonOwningReference): - return builder.PrependUint64Slot(41, nonOwningReference, 0) + builder.PrependUint64Slot(41, nonOwningReference, 0) -def AddNonOwningReference(builder, nonOwningReference): - return MonsterAddNonOwningReference(builder, nonOwningReference) +def AddNonOwningReference(builder: flatbuffers.Builder, nonOwningReference: int): + MonsterAddNonOwningReference(builder, nonOwningReference) def MonsterAddVectorOfNonOwningReferences(builder, vectorOfNonOwningReferences): - return builder.PrependUOffsetTRelativeSlot(42, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfNonOwningReferences), 0) + builder.PrependUOffsetTRelativeSlot(42, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfNonOwningReferences), 0) -def AddVectorOfNonOwningReferences(builder, vectorOfNonOwningReferences): - return MonsterAddVectorOfNonOwningReferences(builder, vectorOfNonOwningReferences) +def AddVectorOfNonOwningReferences(builder: flatbuffers.Builder, vectorOfNonOwningReferences: int): + MonsterAddVectorOfNonOwningReferences(builder, vectorOfNonOwningReferences) def MonsterStartVectorOfNonOwningReferencesVector(builder, numElems): return builder.StartVector(8, numElems, 8) -def StartVectorOfNonOwningReferencesVector(builder, numElems): +def StartVectorOfNonOwningReferencesVector(builder, numElems: int) -> int: return MonsterStartVectorOfNonOwningReferencesVector(builder, numElems) def MonsterAddAnyUniqueType(builder, anyUniqueType): - return builder.PrependUint8Slot(43, anyUniqueType, 0) + builder.PrependUint8Slot(43, anyUniqueType, 0) -def AddAnyUniqueType(builder, anyUniqueType): - return MonsterAddAnyUniqueType(builder, anyUniqueType) +def AddAnyUniqueType(builder: flatbuffers.Builder, anyUniqueType: int): + MonsterAddAnyUniqueType(builder, anyUniqueType) def MonsterAddAnyUnique(builder, anyUnique): - return builder.PrependUOffsetTRelativeSlot(44, flatbuffers.number_types.UOffsetTFlags.py_type(anyUnique), 0) + builder.PrependUOffsetTRelativeSlot(44, flatbuffers.number_types.UOffsetTFlags.py_type(anyUnique), 0) -def AddAnyUnique(builder, anyUnique): - return MonsterAddAnyUnique(builder, anyUnique) +def AddAnyUnique(builder: flatbuffers.Builder, anyUnique: int): + MonsterAddAnyUnique(builder, anyUnique) def MonsterAddAnyAmbiguousType(builder, anyAmbiguousType): - return builder.PrependUint8Slot(45, anyAmbiguousType, 0) + builder.PrependUint8Slot(45, anyAmbiguousType, 0) -def AddAnyAmbiguousType(builder, anyAmbiguousType): - return MonsterAddAnyAmbiguousType(builder, anyAmbiguousType) +def AddAnyAmbiguousType(builder: flatbuffers.Builder, anyAmbiguousType: int): + MonsterAddAnyAmbiguousType(builder, anyAmbiguousType) def MonsterAddAnyAmbiguous(builder, anyAmbiguous): - return builder.PrependUOffsetTRelativeSlot(46, flatbuffers.number_types.UOffsetTFlags.py_type(anyAmbiguous), 0) + builder.PrependUOffsetTRelativeSlot(46, flatbuffers.number_types.UOffsetTFlags.py_type(anyAmbiguous), 0) -def AddAnyAmbiguous(builder, anyAmbiguous): - return MonsterAddAnyAmbiguous(builder, anyAmbiguous) +def AddAnyAmbiguous(builder: flatbuffers.Builder, anyAmbiguous: int): + MonsterAddAnyAmbiguous(builder, anyAmbiguous) def MonsterAddVectorOfEnums(builder, vectorOfEnums): - return builder.PrependUOffsetTRelativeSlot(47, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfEnums), 0) + builder.PrependUOffsetTRelativeSlot(47, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfEnums), 0) -def AddVectorOfEnums(builder, vectorOfEnums): - return MonsterAddVectorOfEnums(builder, vectorOfEnums) +def AddVectorOfEnums(builder: flatbuffers.Builder, vectorOfEnums: int): + MonsterAddVectorOfEnums(builder, vectorOfEnums) def MonsterStartVectorOfEnumsVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def StartVectorOfEnumsVector(builder, numElems): +def StartVectorOfEnumsVector(builder, numElems: int) -> int: return MonsterStartVectorOfEnumsVector(builder, numElems) def MonsterAddSignedEnum(builder, signedEnum): - return builder.PrependInt8Slot(48, signedEnum, -1) + builder.PrependInt8Slot(48, signedEnum, -1) -def AddSignedEnum(builder, signedEnum): - return MonsterAddSignedEnum(builder, signedEnum) +def AddSignedEnum(builder: flatbuffers.Builder, signedEnum: int): + MonsterAddSignedEnum(builder, signedEnum) def MonsterAddTestrequirednestedflatbuffer(builder, testrequirednestedflatbuffer): - return builder.PrependUOffsetTRelativeSlot(49, flatbuffers.number_types.UOffsetTFlags.py_type(testrequirednestedflatbuffer), 0) + builder.PrependUOffsetTRelativeSlot(49, flatbuffers.number_types.UOffsetTFlags.py_type(testrequirednestedflatbuffer), 0) -def AddTestrequirednestedflatbuffer(builder, testrequirednestedflatbuffer): - return MonsterAddTestrequirednestedflatbuffer(builder, testrequirednestedflatbuffer) +def AddTestrequirednestedflatbuffer(builder: flatbuffers.Builder, testrequirednestedflatbuffer: int): + MonsterAddTestrequirednestedflatbuffer(builder, testrequirednestedflatbuffer) def MonsterStartTestrequirednestedflatbufferVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def StartTestrequirednestedflatbufferVector(builder, numElems): +def StartTestrequirednestedflatbufferVector(builder, numElems: int) -> int: return MonsterStartTestrequirednestedflatbufferVector(builder, numElems) def MonsterMakeTestrequirednestedflatbufferVectorFromBytes(builder, bytes): @@ -1301,82 +1301,82 @@ def MonsterMakeTestrequirednestedflatbufferVectorFromBytes(builder, bytes): def MakeTestrequirednestedflatbufferVectorFromBytes(builder, bytes): return MonsterMakeTestrequirednestedflatbufferVectorFromBytes(builder, bytes) def MonsterAddScalarKeySortedTables(builder, scalarKeySortedTables): - return builder.PrependUOffsetTRelativeSlot(50, flatbuffers.number_types.UOffsetTFlags.py_type(scalarKeySortedTables), 0) + builder.PrependUOffsetTRelativeSlot(50, flatbuffers.number_types.UOffsetTFlags.py_type(scalarKeySortedTables), 0) -def AddScalarKeySortedTables(builder, scalarKeySortedTables): - return MonsterAddScalarKeySortedTables(builder, scalarKeySortedTables) +def AddScalarKeySortedTables(builder: flatbuffers.Builder, scalarKeySortedTables: int): + MonsterAddScalarKeySortedTables(builder, scalarKeySortedTables) def MonsterStartScalarKeySortedTablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartScalarKeySortedTablesVector(builder, numElems): +def StartScalarKeySortedTablesVector(builder, numElems: int) -> int: return MonsterStartScalarKeySortedTablesVector(builder, numElems) def MonsterAddNativeInline(builder, nativeInline): - return builder.PrependStructSlot(51, flatbuffers.number_types.UOffsetTFlags.py_type(nativeInline), 0) + builder.PrependStructSlot(51, flatbuffers.number_types.UOffsetTFlags.py_type(nativeInline), 0) -def AddNativeInline(builder, nativeInline): - return MonsterAddNativeInline(builder, nativeInline) +def AddNativeInline(builder: flatbuffers.Builder, nativeInline: Any): + MonsterAddNativeInline(builder, nativeInline) def MonsterAddLongEnumNonEnumDefault(builder, longEnumNonEnumDefault): - return builder.PrependUint64Slot(52, longEnumNonEnumDefault, 0) + builder.PrependUint64Slot(52, longEnumNonEnumDefault, 0) -def AddLongEnumNonEnumDefault(builder, longEnumNonEnumDefault): - return MonsterAddLongEnumNonEnumDefault(builder, longEnumNonEnumDefault) +def AddLongEnumNonEnumDefault(builder: flatbuffers.Builder, longEnumNonEnumDefault: int): + MonsterAddLongEnumNonEnumDefault(builder, longEnumNonEnumDefault) def MonsterAddLongEnumNormalDefault(builder, longEnumNormalDefault): - return builder.PrependUint64Slot(53, longEnumNormalDefault, 2) + builder.PrependUint64Slot(53, longEnumNormalDefault, 2) -def AddLongEnumNormalDefault(builder, longEnumNormalDefault): - return MonsterAddLongEnumNormalDefault(builder, longEnumNormalDefault) +def AddLongEnumNormalDefault(builder: flatbuffers.Builder, longEnumNormalDefault: int): + MonsterAddLongEnumNormalDefault(builder, longEnumNormalDefault) def MonsterAddNanDefault(builder, nanDefault): - return builder.PrependFloat32Slot(54, nanDefault, float('nan')) + builder.PrependFloat32Slot(54, nanDefault, float('nan')) -def AddNanDefault(builder, nanDefault): - return MonsterAddNanDefault(builder, nanDefault) +def AddNanDefault(builder: flatbuffers.Builder, nanDefault: float): + MonsterAddNanDefault(builder, nanDefault) def MonsterAddInfDefault(builder, infDefault): - return builder.PrependFloat32Slot(55, infDefault, float('inf')) + builder.PrependFloat32Slot(55, infDefault, float('inf')) -def AddInfDefault(builder, infDefault): - return MonsterAddInfDefault(builder, infDefault) +def AddInfDefault(builder: flatbuffers.Builder, infDefault: float): + MonsterAddInfDefault(builder, infDefault) def MonsterAddPositiveInfDefault(builder, positiveInfDefault): - return builder.PrependFloat32Slot(56, positiveInfDefault, float('inf')) + builder.PrependFloat32Slot(56, positiveInfDefault, float('inf')) -def AddPositiveInfDefault(builder, positiveInfDefault): - return MonsterAddPositiveInfDefault(builder, positiveInfDefault) +def AddPositiveInfDefault(builder: flatbuffers.Builder, positiveInfDefault: float): + MonsterAddPositiveInfDefault(builder, positiveInfDefault) def MonsterAddInfinityDefault(builder, infinityDefault): - return builder.PrependFloat32Slot(57, infinityDefault, float('inf')) + builder.PrependFloat32Slot(57, infinityDefault, float('inf')) -def AddInfinityDefault(builder, infinityDefault): - return MonsterAddInfinityDefault(builder, infinityDefault) +def AddInfinityDefault(builder: flatbuffers.Builder, infinityDefault: float): + MonsterAddInfinityDefault(builder, infinityDefault) def MonsterAddPositiveInfinityDefault(builder, positiveInfinityDefault): - return builder.PrependFloat32Slot(58, positiveInfinityDefault, float('inf')) + builder.PrependFloat32Slot(58, positiveInfinityDefault, float('inf')) -def AddPositiveInfinityDefault(builder, positiveInfinityDefault): - return MonsterAddPositiveInfinityDefault(builder, positiveInfinityDefault) +def AddPositiveInfinityDefault(builder: flatbuffers.Builder, positiveInfinityDefault: float): + MonsterAddPositiveInfinityDefault(builder, positiveInfinityDefault) def MonsterAddNegativeInfDefault(builder, negativeInfDefault): - return builder.PrependFloat32Slot(59, negativeInfDefault, float('-inf')) + builder.PrependFloat32Slot(59, negativeInfDefault, float('-inf')) -def AddNegativeInfDefault(builder, negativeInfDefault): - return MonsterAddNegativeInfDefault(builder, negativeInfDefault) +def AddNegativeInfDefault(builder: flatbuffers.Builder, negativeInfDefault: float): + MonsterAddNegativeInfDefault(builder, negativeInfDefault) def MonsterAddNegativeInfinityDefault(builder, negativeInfinityDefault): - return builder.PrependFloat32Slot(60, negativeInfinityDefault, float('-inf')) + builder.PrependFloat32Slot(60, negativeInfinityDefault, float('-inf')) -def AddNegativeInfinityDefault(builder, negativeInfinityDefault): - return MonsterAddNegativeInfinityDefault(builder, negativeInfinityDefault) +def AddNegativeInfinityDefault(builder: flatbuffers.Builder, negativeInfinityDefault: float): + MonsterAddNegativeInfinityDefault(builder, negativeInfinityDefault) def MonsterAddDoubleInfDefault(builder, doubleInfDefault): - return builder.PrependFloat64Slot(61, doubleInfDefault, float('inf')) + builder.PrependFloat64Slot(61, doubleInfDefault, float('inf')) -def AddDoubleInfDefault(builder, doubleInfDefault): - return MonsterAddDoubleInfDefault(builder, doubleInfDefault) +def AddDoubleInfDefault(builder: flatbuffers.Builder, doubleInfDefault: float): + MonsterAddDoubleInfDefault(builder, doubleInfDefault) def MonsterEnd(builder): return builder.EndObject() diff --git a/tests/MyGame/Example/NestedStruct.py b/tests/MyGame/Example/NestedStruct.py index 7f8d18ef..d5d672a2 100644 --- a/tests/MyGame/Example/NestedStruct.py +++ b/tests/MyGame/Example/NestedStruct.py @@ -4,17 +4,18 @@ import flatbuffers from flatbuffers.compat import import_numpy +from typing import Any np = import_numpy() class NestedStruct(object): __slots__ = ['_tab'] @classmethod - def SizeOf(cls): + def SizeOf(cls) -> int: return 32 # NestedStruct - def Init(self, buf, pos): + def Init(self, buf: bytes, pos: int): self._tab = flatbuffers.table.Table(buf, pos) # NestedStruct @@ -31,11 +32,11 @@ class NestedStruct(object): return self._tab.GetArrayAsNumpy(flatbuffers.number_types.Int32Flags, self._tab.Pos + 0, self.ALength()) # NestedStruct - def ALength(self): + def ALength(self) -> int: return 2 # NestedStruct - def AIsNone(self): + def AIsNone(self) -> bool: return False # NestedStruct @@ -54,11 +55,11 @@ class NestedStruct(object): return self._tab.GetArrayAsNumpy(flatbuffers.number_types.Int8Flags, self._tab.Pos + 9, self.CLength()) # NestedStruct - def CLength(self): + def CLength(self) -> int: return 2 # NestedStruct - def CIsNone(self): + def CIsNone(self) -> bool: return False # NestedStruct @@ -75,11 +76,11 @@ class NestedStruct(object): return self._tab.GetArrayAsNumpy(flatbuffers.number_types.Int64Flags, self._tab.Pos + 16, self.DLength()) # NestedStruct - def DLength(self): + def DLength(self) -> int: return 2 # NestedStruct - def DIsNone(self): + def DIsNone(self) -> bool: return False diff --git a/tests/MyGame/Example/NestedUnion/NestedUnionTest.py b/tests/MyGame/Example/NestedUnion/NestedUnionTest.py index 33c2a441..7540b6e8 100644 --- a/tests/MyGame/Example/NestedUnion/NestedUnionTest.py +++ b/tests/MyGame/Example/NestedUnion/NestedUnionTest.py @@ -4,13 +4,16 @@ import flatbuffers from flatbuffers.compat import import_numpy +from typing import Any +from flatbuffers.table import Table +from typing import Optional np = import_numpy() class NestedUnionTest(object): __slots__ = ['_tab'] @classmethod - def GetRootAs(cls, buf, offset=0): + def GetRootAs(cls, buf, offset: int = 0): n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) x = NestedUnionTest() x.Init(buf, n + offset) @@ -21,11 +24,11 @@ class NestedUnionTest(object): """This method is deprecated. Please switch to GetRootAs.""" return cls.GetRootAs(buf, offset) # NestedUnionTest - def Init(self, buf, pos): + def Init(self, buf: bytes, pos: int): self._tab = flatbuffers.table.Table(buf, pos) # NestedUnionTest - def Name(self): + def Name(self) -> Optional[str]: o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) if o != 0: return self._tab.String(o + self._tab.Pos) @@ -39,10 +42,9 @@ class NestedUnionTest(object): return 0 # NestedUnionTest - def Data(self): + def Data(self) -> Optional[flatbuffers.table.Table]: o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) if o != 0: - from flatbuffers.table import Table obj = Table(bytearray(), 0) self._tab.Union(obj, o) return obj @@ -55,40 +57,40 @@ class NestedUnionTest(object): return self._tab.Get(flatbuffers.number_types.Int16Flags, o + self._tab.Pos) return 0 -def NestedUnionTestStart(builder): - return builder.StartObject(4) +def NestedUnionTestStart(builder: flatbuffers.Builder): + builder.StartObject(4) -def Start(builder): - return NestedUnionTestStart(builder) +def Start(builder: flatbuffers.Builder): + NestedUnionTestStart(builder) -def NestedUnionTestAddName(builder, name): - return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) +def NestedUnionTestAddName(builder: flatbuffers.Builder, name: int): + builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) -def AddName(builder, name): - return NestedUnionTestAddName(builder, name) +def AddName(builder: flatbuffers.Builder, name: int): + NestedUnionTestAddName(builder, name) -def NestedUnionTestAddDataType(builder, dataType): - return builder.PrependUint8Slot(1, dataType, 0) +def NestedUnionTestAddDataType(builder: flatbuffers.Builder, dataType: int): + builder.PrependUint8Slot(1, dataType, 0) -def AddDataType(builder, dataType): - return NestedUnionTestAddDataType(builder, dataType) +def AddDataType(builder: flatbuffers.Builder, dataType: int): + NestedUnionTestAddDataType(builder, dataType) -def NestedUnionTestAddData(builder, data): - return builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(data), 0) +def NestedUnionTestAddData(builder: flatbuffers.Builder, data: int): + builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(data), 0) -def AddData(builder, data): - return NestedUnionTestAddData(builder, data) +def AddData(builder: flatbuffers.Builder, data: int): + NestedUnionTestAddData(builder, data) -def NestedUnionTestAddId(builder, id): - return builder.PrependInt16Slot(3, id, 0) +def NestedUnionTestAddId(builder: flatbuffers.Builder, id: int): + builder.PrependInt16Slot(3, id, 0) -def AddId(builder, id): - return NestedUnionTestAddId(builder, id) +def AddId(builder: flatbuffers.Builder, id: int): + NestedUnionTestAddId(builder, id) -def NestedUnionTestEnd(builder): +def NestedUnionTestEnd(builder: flatbuffers.Builder) -> int: return builder.EndObject() -def End(builder): +def End(builder: flatbuffers.Builder) -> int: return NestedUnionTestEnd(builder) import MyGame.Example.NestedUnion.Any diff --git a/tests/MyGame/Example/NestedUnion/Test.py b/tests/MyGame/Example/NestedUnion/Test.py index 143d1dfd..e4e90be2 100644 --- a/tests/MyGame/Example/NestedUnion/Test.py +++ b/tests/MyGame/Example/NestedUnion/Test.py @@ -4,17 +4,18 @@ import flatbuffers from flatbuffers.compat import import_numpy +from typing import Any np = import_numpy() class Test(object): __slots__ = ['_tab'] @classmethod - def SizeOf(cls): + def SizeOf(cls) -> int: return 4 # Test - def Init(self, buf, pos): + def Init(self, buf: bytes, pos: int): self._tab = flatbuffers.table.Table(buf, pos) # Test diff --git a/tests/MyGame/Example/NestedUnion/TestSimpleTableWithEnum.py b/tests/MyGame/Example/NestedUnion/TestSimpleTableWithEnum.py index b3ad74f7..9b7ef28c 100644 --- a/tests/MyGame/Example/NestedUnion/TestSimpleTableWithEnum.py +++ b/tests/MyGame/Example/NestedUnion/TestSimpleTableWithEnum.py @@ -4,13 +4,14 @@ import flatbuffers from flatbuffers.compat import import_numpy +from typing import Any np = import_numpy() class TestSimpleTableWithEnum(object): __slots__ = ['_tab'] @classmethod - def GetRootAs(cls, buf, offset=0): + def GetRootAs(cls, buf, offset: int = 0): n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) x = TestSimpleTableWithEnum() x.Init(buf, n + offset) @@ -21,7 +22,7 @@ class TestSimpleTableWithEnum(object): """This method is deprecated. Please switch to GetRootAs.""" return cls.GetRootAs(buf, offset) # TestSimpleTableWithEnum - def Init(self, buf, pos): + def Init(self, buf: bytes, pos: int): self._tab = flatbuffers.table.Table(buf, pos) # TestSimpleTableWithEnum @@ -31,22 +32,22 @@ class TestSimpleTableWithEnum(object): return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos) return 2 -def TestSimpleTableWithEnumStart(builder): - return builder.StartObject(1) +def TestSimpleTableWithEnumStart(builder: flatbuffers.Builder): + builder.StartObject(1) -def Start(builder): - return TestSimpleTableWithEnumStart(builder) +def Start(builder: flatbuffers.Builder): + TestSimpleTableWithEnumStart(builder) -def TestSimpleTableWithEnumAddColor(builder, color): - return builder.PrependUint8Slot(0, color, 2) +def TestSimpleTableWithEnumAddColor(builder: flatbuffers.Builder, color: int): + builder.PrependUint8Slot(0, color, 2) -def AddColor(builder, color): - return TestSimpleTableWithEnumAddColor(builder, color) +def AddColor(builder: flatbuffers.Builder, color: int): + TestSimpleTableWithEnumAddColor(builder, color) -def TestSimpleTableWithEnumEnd(builder): +def TestSimpleTableWithEnumEnd(builder: flatbuffers.Builder) -> int: return builder.EndObject() -def End(builder): +def End(builder: flatbuffers.Builder) -> int: return TestSimpleTableWithEnumEnd(builder) diff --git a/tests/MyGame/Example/NestedUnion/Vec3.py b/tests/MyGame/Example/NestedUnion/Vec3.py index 915f5801..11feab11 100644 --- a/tests/MyGame/Example/NestedUnion/Vec3.py +++ b/tests/MyGame/Example/NestedUnion/Vec3.py @@ -4,13 +4,16 @@ import flatbuffers from flatbuffers.compat import import_numpy +from typing import Any +from .MyGame.Example.NestedUnion.Test import Test +from typing import Optional np = import_numpy() class Vec3(object): __slots__ = ['_tab'] @classmethod - def GetRootAs(cls, buf, offset=0): + def GetRootAs(cls, buf, offset: int = 0): n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) x = Vec3() x.Init(buf, n + offset) @@ -21,7 +24,7 @@ class Vec3(object): """This method is deprecated. Please switch to GetRootAs.""" return cls.GetRootAs(buf, offset) # Vec3 - def Init(self, buf, pos): + def Init(self, buf: bytes, pos: int): self._tab = flatbuffers.table.Table(buf, pos) # Vec3 @@ -60,62 +63,61 @@ class Vec3(object): return 0 # Vec3 - def Test3(self): + def Test3(self) -> Optional[Test]: o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) if o != 0: x = o + self._tab.Pos - from MyGame.Example.NestedUnion.Test import Test obj = Test() obj.Init(self._tab.Bytes, x) return obj return None -def Vec3Start(builder): - return builder.StartObject(6) +def Vec3Start(builder: flatbuffers.Builder): + builder.StartObject(6) -def Start(builder): - return Vec3Start(builder) +def Start(builder: flatbuffers.Builder): + Vec3Start(builder) -def Vec3AddX(builder, x): - return builder.PrependFloat64Slot(0, x, 0.0) +def Vec3AddX(builder: flatbuffers.Builder, x: float): + builder.PrependFloat64Slot(0, x, 0.0) -def AddX(builder, x): - return Vec3AddX(builder, x) +def AddX(builder: flatbuffers.Builder, x: float): + Vec3AddX(builder, x) -def Vec3AddY(builder, y): - return builder.PrependFloat64Slot(1, y, 0.0) +def Vec3AddY(builder: flatbuffers.Builder, y: float): + builder.PrependFloat64Slot(1, y, 0.0) -def AddY(builder, y): - return Vec3AddY(builder, y) +def AddY(builder: flatbuffers.Builder, y: float): + Vec3AddY(builder, y) -def Vec3AddZ(builder, z): - return builder.PrependFloat64Slot(2, z, 0.0) +def Vec3AddZ(builder: flatbuffers.Builder, z: float): + builder.PrependFloat64Slot(2, z, 0.0) -def AddZ(builder, z): - return Vec3AddZ(builder, z) +def AddZ(builder: flatbuffers.Builder, z: float): + Vec3AddZ(builder, z) -def Vec3AddTest1(builder, test1): - return builder.PrependFloat64Slot(3, test1, 0.0) +def Vec3AddTest1(builder: flatbuffers.Builder, test1: float): + builder.PrependFloat64Slot(3, test1, 0.0) -def AddTest1(builder, test1): - return Vec3AddTest1(builder, test1) +def AddTest1(builder: flatbuffers.Builder, test1: float): + Vec3AddTest1(builder, test1) -def Vec3AddTest2(builder, test2): - return builder.PrependUint8Slot(4, test2, 0) +def Vec3AddTest2(builder: flatbuffers.Builder, test2: int): + builder.PrependUint8Slot(4, test2, 0) -def AddTest2(builder, test2): - return Vec3AddTest2(builder, test2) +def AddTest2(builder: flatbuffers.Builder, test2: int): + Vec3AddTest2(builder, test2) -def Vec3AddTest3(builder, test3): - return builder.PrependStructSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(test3), 0) +def Vec3AddTest3(builder: flatbuffers.Builder, test3: Any): + builder.PrependStructSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(test3), 0) -def AddTest3(builder, test3): - return Vec3AddTest3(builder, test3) +def AddTest3(builder: flatbuffers.Builder, test3: Any): + Vec3AddTest3(builder, test3) -def Vec3End(builder): +def Vec3End(builder: flatbuffers.Builder) -> int: return builder.EndObject() -def End(builder): +def End(builder: flatbuffers.Builder) -> int: return Vec3End(builder) import MyGame.Example.NestedUnion.Test diff --git a/tests/MyGame/Example/Referrable.py b/tests/MyGame/Example/Referrable.py index e5081e1a..203c9341 100644 --- a/tests/MyGame/Example/Referrable.py +++ b/tests/MyGame/Example/Referrable.py @@ -36,16 +36,16 @@ class Referrable(object): return 0 def ReferrableStart(builder): - return builder.StartObject(1) + builder.StartObject(1) def Start(builder): - return ReferrableStart(builder) + ReferrableStart(builder) def ReferrableAddId(builder, id): - return builder.PrependUint64Slot(0, id, 0) + builder.PrependUint64Slot(0, id, 0) -def AddId(builder, id): - return ReferrableAddId(builder, id) +def AddId(builder: flatbuffers.Builder, id: int): + ReferrableAddId(builder, id) def ReferrableEnd(builder): return builder.EndObject() diff --git a/tests/MyGame/Example/Stat.py b/tests/MyGame/Example/Stat.py index 00ca1a46..4f175574 100644 --- a/tests/MyGame/Example/Stat.py +++ b/tests/MyGame/Example/Stat.py @@ -50,28 +50,28 @@ class Stat(object): return 0 def StatStart(builder): - return builder.StartObject(3) + builder.StartObject(3) def Start(builder): - return StatStart(builder) + StatStart(builder) def StatAddId(builder, id): - return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(id), 0) + builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(id), 0) -def AddId(builder, id): - return StatAddId(builder, id) +def AddId(builder: flatbuffers.Builder, id: int): + StatAddId(builder, id) def StatAddVal(builder, val): - return builder.PrependInt64Slot(1, val, 0) + builder.PrependInt64Slot(1, val, 0) -def AddVal(builder, val): - return StatAddVal(builder, val) +def AddVal(builder: flatbuffers.Builder, val: int): + StatAddVal(builder, val) def StatAddCount(builder, count): - return builder.PrependUint16Slot(2, count, 0) + builder.PrependUint16Slot(2, count, 0) -def AddCount(builder, count): - return StatAddCount(builder, count) +def AddCount(builder: flatbuffers.Builder, count: int): + StatAddCount(builder, count) def StatEnd(builder): return builder.EndObject() diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.py b/tests/MyGame/Example/TestSimpleTableWithEnum.py index 99e5c41b..856442c8 100644 --- a/tests/MyGame/Example/TestSimpleTableWithEnum.py +++ b/tests/MyGame/Example/TestSimpleTableWithEnum.py @@ -36,16 +36,16 @@ class TestSimpleTableWithEnum(object): return 2 def TestSimpleTableWithEnumStart(builder): - return builder.StartObject(1) + builder.StartObject(1) def Start(builder): - return TestSimpleTableWithEnumStart(builder) + TestSimpleTableWithEnumStart(builder) def TestSimpleTableWithEnumAddColor(builder, color): - return builder.PrependUint8Slot(0, color, 2) + builder.PrependUint8Slot(0, color, 2) -def AddColor(builder, color): - return TestSimpleTableWithEnumAddColor(builder, color) +def AddColor(builder: flatbuffers.Builder, color: int): + TestSimpleTableWithEnumAddColor(builder, color) def TestSimpleTableWithEnumEnd(builder): return builder.EndObject() diff --git a/tests/MyGame/Example/TypeAliases.py b/tests/MyGame/Example/TypeAliases.py index 8fb33b9d..27c6c4f9 100644 --- a/tests/MyGame/Example/TypeAliases.py +++ b/tests/MyGame/Example/TypeAliases.py @@ -153,93 +153,93 @@ class TypeAliases(object): return o == 0 def TypeAliasesStart(builder): - return builder.StartObject(12) + builder.StartObject(12) def Start(builder): - return TypeAliasesStart(builder) + TypeAliasesStart(builder) def TypeAliasesAddI8(builder, i8): - return builder.PrependInt8Slot(0, i8, 0) + builder.PrependInt8Slot(0, i8, 0) -def AddI8(builder, i8): - return TypeAliasesAddI8(builder, i8) +def AddI8(builder: flatbuffers.Builder, i8: int): + TypeAliasesAddI8(builder, i8) def TypeAliasesAddU8(builder, u8): - return builder.PrependUint8Slot(1, u8, 0) + builder.PrependUint8Slot(1, u8, 0) -def AddU8(builder, u8): - return TypeAliasesAddU8(builder, u8) +def AddU8(builder: flatbuffers.Builder, u8: int): + TypeAliasesAddU8(builder, u8) def TypeAliasesAddI16(builder, i16): - return builder.PrependInt16Slot(2, i16, 0) + builder.PrependInt16Slot(2, i16, 0) -def AddI16(builder, i16): - return TypeAliasesAddI16(builder, i16) +def AddI16(builder: flatbuffers.Builder, i16: int): + TypeAliasesAddI16(builder, i16) def TypeAliasesAddU16(builder, u16): - return builder.PrependUint16Slot(3, u16, 0) + builder.PrependUint16Slot(3, u16, 0) -def AddU16(builder, u16): - return TypeAliasesAddU16(builder, u16) +def AddU16(builder: flatbuffers.Builder, u16: int): + TypeAliasesAddU16(builder, u16) def TypeAliasesAddI32(builder, i32): - return builder.PrependInt32Slot(4, i32, 0) + builder.PrependInt32Slot(4, i32, 0) -def AddI32(builder, i32): - return TypeAliasesAddI32(builder, i32) +def AddI32(builder: flatbuffers.Builder, i32: int): + TypeAliasesAddI32(builder, i32) def TypeAliasesAddU32(builder, u32): - return builder.PrependUint32Slot(5, u32, 0) + builder.PrependUint32Slot(5, u32, 0) -def AddU32(builder, u32): - return TypeAliasesAddU32(builder, u32) +def AddU32(builder: flatbuffers.Builder, u32: int): + TypeAliasesAddU32(builder, u32) def TypeAliasesAddI64(builder, i64): - return builder.PrependInt64Slot(6, i64, 0) + builder.PrependInt64Slot(6, i64, 0) -def AddI64(builder, i64): - return TypeAliasesAddI64(builder, i64) +def AddI64(builder: flatbuffers.Builder, i64: int): + TypeAliasesAddI64(builder, i64) def TypeAliasesAddU64(builder, u64): - return builder.PrependUint64Slot(7, u64, 0) + builder.PrependUint64Slot(7, u64, 0) -def AddU64(builder, u64): - return TypeAliasesAddU64(builder, u64) +def AddU64(builder: flatbuffers.Builder, u64: int): + TypeAliasesAddU64(builder, u64) def TypeAliasesAddF32(builder, f32): - return builder.PrependFloat32Slot(8, f32, 0.0) + builder.PrependFloat32Slot(8, f32, 0.0) -def AddF32(builder, f32): - return TypeAliasesAddF32(builder, f32) +def AddF32(builder: flatbuffers.Builder, f32: float): + TypeAliasesAddF32(builder, f32) def TypeAliasesAddF64(builder, f64): - return builder.PrependFloat64Slot(9, f64, 0.0) + builder.PrependFloat64Slot(9, f64, 0.0) -def AddF64(builder, f64): - return TypeAliasesAddF64(builder, f64) +def AddF64(builder: flatbuffers.Builder, f64: float): + TypeAliasesAddF64(builder, f64) def TypeAliasesAddV8(builder, v8): - return builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(v8), 0) + builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(v8), 0) -def AddV8(builder, v8): - return TypeAliasesAddV8(builder, v8) +def AddV8(builder: flatbuffers.Builder, v8: int): + TypeAliasesAddV8(builder, v8) def TypeAliasesStartV8Vector(builder, numElems): return builder.StartVector(1, numElems, 1) -def StartV8Vector(builder, numElems): +def StartV8Vector(builder, numElems: int) -> int: return TypeAliasesStartV8Vector(builder, numElems) def TypeAliasesAddVf64(builder, vf64): - return builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(vf64), 0) + builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(vf64), 0) -def AddVf64(builder, vf64): - return TypeAliasesAddVf64(builder, vf64) +def AddVf64(builder: flatbuffers.Builder, vf64: int): + TypeAliasesAddVf64(builder, vf64) def TypeAliasesStartVf64Vector(builder, numElems): return builder.StartVector(8, numElems, 8) -def StartVf64Vector(builder, numElems): +def StartVf64Vector(builder, numElems: int) -> int: return TypeAliasesStartVf64Vector(builder, numElems) def TypeAliasesEnd(builder): diff --git a/tests/MyGame/Example2/Monster.py b/tests/MyGame/Example2/Monster.py index 965c4ffd..41c43e9e 100644 --- a/tests/MyGame/Example2/Monster.py +++ b/tests/MyGame/Example2/Monster.py @@ -29,10 +29,10 @@ class Monster(object): self._tab = flatbuffers.table.Table(buf, pos) def MonsterStart(builder): - return builder.StartObject(0) + builder.StartObject(0) def Start(builder): - return MonsterStart(builder) + MonsterStart(builder) def MonsterEnd(builder): return builder.EndObject() diff --git a/tests/MyGame/InParentNamespace.py b/tests/MyGame/InParentNamespace.py index bd10e695..adbce917 100644 --- a/tests/MyGame/InParentNamespace.py +++ b/tests/MyGame/InParentNamespace.py @@ -29,10 +29,10 @@ class InParentNamespace(object): self._tab = flatbuffers.table.Table(buf, pos) def InParentNamespaceStart(builder): - return builder.StartObject(0) + builder.StartObject(0) def Start(builder): - return InParentNamespaceStart(builder) + InParentNamespaceStart(builder) def InParentNamespaceEnd(builder): return builder.EndObject() diff --git a/tests/MyGame/MonsterExtra.py b/tests/MyGame/MonsterExtra.py index 10e380b7..d9e18361 100644 --- a/tests/MyGame/MonsterExtra.py +++ b/tests/MyGame/MonsterExtra.py @@ -4,13 +4,14 @@ import flatbuffers from flatbuffers.compat import import_numpy +from typing import Any np = import_numpy() class MonsterExtra(object): __slots__ = ['_tab'] @classmethod - def GetRootAs(cls, buf, offset=0): + def GetRootAs(cls, buf, offset: int = 0): n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) x = MonsterExtra() x.Init(buf, n + offset) @@ -25,7 +26,7 @@ class MonsterExtra(object): return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x4D\x4F\x4E\x45", size_prefixed=size_prefixed) # MonsterExtra - def Init(self, buf, pos): + def Init(self, buf: bytes, pos: int): self._tab = flatbuffers.table.Table(buf, pos) # MonsterExtra @@ -85,7 +86,7 @@ class MonsterExtra(object): return float('-inf') # MonsterExtra - def Dvec(self, j): + def Dvec(self, j: int): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(20)) if o != 0: a = self._tab.Vector(o) @@ -100,19 +101,19 @@ class MonsterExtra(object): return 0 # MonsterExtra - def DvecLength(self): + def DvecLength(self) -> int: o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(20)) if o != 0: return self._tab.VectorLen(o) return 0 # MonsterExtra - def DvecIsNone(self): + def DvecIsNone(self) -> bool: o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(20)) return o == 0 # MonsterExtra - def Fvec(self, j): + def Fvec(self, j: int): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(22)) if o != 0: a = self._tab.Vector(o) @@ -127,99 +128,99 @@ class MonsterExtra(object): return 0 # MonsterExtra - def FvecLength(self): + def FvecLength(self) -> int: o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(22)) if o != 0: return self._tab.VectorLen(o) return 0 # MonsterExtra - def FvecIsNone(self): + def FvecIsNone(self) -> bool: o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(22)) return o == 0 -def MonsterExtraStart(builder): - return builder.StartObject(11) +def MonsterExtraStart(builder: flatbuffers.Builder): + builder.StartObject(11) -def Start(builder): - return MonsterExtraStart(builder) +def Start(builder: flatbuffers.Builder): + MonsterExtraStart(builder) -def MonsterExtraAddD0(builder, d0): - return builder.PrependFloat64Slot(0, d0, float('nan')) +def MonsterExtraAddD0(builder: flatbuffers.Builder, d0: float): + builder.PrependFloat64Slot(0, d0, float('nan')) -def AddD0(builder, d0): - return MonsterExtraAddD0(builder, d0) +def AddD0(builder: flatbuffers.Builder, d0: float): + MonsterExtraAddD0(builder, d0) -def MonsterExtraAddD1(builder, d1): - return builder.PrependFloat64Slot(1, d1, float('nan')) +def MonsterExtraAddD1(builder: flatbuffers.Builder, d1: float): + builder.PrependFloat64Slot(1, d1, float('nan')) -def AddD1(builder, d1): - return MonsterExtraAddD1(builder, d1) +def AddD1(builder: flatbuffers.Builder, d1: float): + MonsterExtraAddD1(builder, d1) -def MonsterExtraAddD2(builder, d2): - return builder.PrependFloat64Slot(2, d2, float('inf')) +def MonsterExtraAddD2(builder: flatbuffers.Builder, d2: float): + builder.PrependFloat64Slot(2, d2, float('inf')) -def AddD2(builder, d2): - return MonsterExtraAddD2(builder, d2) +def AddD2(builder: flatbuffers.Builder, d2: float): + MonsterExtraAddD2(builder, d2) -def MonsterExtraAddD3(builder, d3): - return builder.PrependFloat64Slot(3, d3, float('-inf')) +def MonsterExtraAddD3(builder: flatbuffers.Builder, d3: float): + builder.PrependFloat64Slot(3, d3, float('-inf')) -def AddD3(builder, d3): - return MonsterExtraAddD3(builder, d3) +def AddD3(builder: flatbuffers.Builder, d3: float): + MonsterExtraAddD3(builder, d3) -def MonsterExtraAddF0(builder, f0): - return builder.PrependFloat32Slot(4, f0, float('nan')) +def MonsterExtraAddF0(builder: flatbuffers.Builder, f0: float): + builder.PrependFloat32Slot(4, f0, float('nan')) -def AddF0(builder, f0): - return MonsterExtraAddF0(builder, f0) +def AddF0(builder: flatbuffers.Builder, f0: float): + MonsterExtraAddF0(builder, f0) -def MonsterExtraAddF1(builder, f1): - return builder.PrependFloat32Slot(5, f1, float('nan')) +def MonsterExtraAddF1(builder: flatbuffers.Builder, f1: float): + builder.PrependFloat32Slot(5, f1, float('nan')) -def AddF1(builder, f1): - return MonsterExtraAddF1(builder, f1) +def AddF1(builder: flatbuffers.Builder, f1: float): + MonsterExtraAddF1(builder, f1) -def MonsterExtraAddF2(builder, f2): - return builder.PrependFloat32Slot(6, f2, float('inf')) +def MonsterExtraAddF2(builder: flatbuffers.Builder, f2: float): + builder.PrependFloat32Slot(6, f2, float('inf')) -def AddF2(builder, f2): - return MonsterExtraAddF2(builder, f2) +def AddF2(builder: flatbuffers.Builder, f2: float): + MonsterExtraAddF2(builder, f2) -def MonsterExtraAddF3(builder, f3): - return builder.PrependFloat32Slot(7, f3, float('-inf')) +def MonsterExtraAddF3(builder: flatbuffers.Builder, f3: float): + builder.PrependFloat32Slot(7, f3, float('-inf')) -def AddF3(builder, f3): - return MonsterExtraAddF3(builder, f3) +def AddF3(builder: flatbuffers.Builder, f3: float): + MonsterExtraAddF3(builder, f3) -def MonsterExtraAddDvec(builder, dvec): - return builder.PrependUOffsetTRelativeSlot(8, flatbuffers.number_types.UOffsetTFlags.py_type(dvec), 0) +def MonsterExtraAddDvec(builder: flatbuffers.Builder, dvec: int): + builder.PrependUOffsetTRelativeSlot(8, flatbuffers.number_types.UOffsetTFlags.py_type(dvec), 0) -def AddDvec(builder, dvec): - return MonsterExtraAddDvec(builder, dvec) +def AddDvec(builder: flatbuffers.Builder, dvec: int): + MonsterExtraAddDvec(builder, dvec) -def MonsterExtraStartDvecVector(builder, numElems): +def MonsterExtraStartDvecVector(builder, numElems: int) -> int: return builder.StartVector(8, numElems, 8) -def StartDvecVector(builder, numElems): +def StartDvecVector(builder, numElems: int) -> int: return MonsterExtraStartDvecVector(builder, numElems) -def MonsterExtraAddFvec(builder, fvec): - return builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(fvec), 0) +def MonsterExtraAddFvec(builder: flatbuffers.Builder, fvec: int): + builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(fvec), 0) -def AddFvec(builder, fvec): - return MonsterExtraAddFvec(builder, fvec) +def AddFvec(builder: flatbuffers.Builder, fvec: int): + MonsterExtraAddFvec(builder, fvec) -def MonsterExtraStartFvecVector(builder, numElems): +def MonsterExtraStartFvecVector(builder, numElems: int) -> int: return builder.StartVector(4, numElems, 4) -def StartFvecVector(builder, numElems): +def StartFvecVector(builder, numElems: int) -> int: return MonsterExtraStartFvecVector(builder, numElems) -def MonsterExtraEnd(builder): +def MonsterExtraEnd(builder: flatbuffers.Builder) -> int: return builder.EndObject() -def End(builder): +def End(builder: flatbuffers.Builder) -> int: return MonsterExtraEnd(builder) try: diff --git a/tests/monster_test_generated.py b/tests/monster_test_generated.py index 36bbb602..2acdf6ce 100644 --- a/tests/monster_test_generated.py +++ b/tests/monster_test_generated.py @@ -109,7 +109,7 @@ class InParentNamespace(object): self._tab = flatbuffers.table.Table(buf, pos) def InParentNamespaceStart(builder): - return builder.StartObject(0) + builder.StartObject(0) def InParentNamespaceEnd(builder): return builder.EndObject() @@ -174,7 +174,7 @@ class Monster(object): self._tab = flatbuffers.table.Table(buf, pos) def MonsterStart(builder): - return builder.StartObject(0) + builder.StartObject(0) def MonsterEnd(builder): return builder.EndObject() @@ -306,10 +306,10 @@ class TestSimpleTableWithEnum(object): return 2 def TestSimpleTableWithEnumStart(builder): - return builder.StartObject(1) + builder.StartObject(1) def TestSimpleTableWithEnumAddColor(builder, color): - return builder.PrependUint8Slot(0, color, 2) + builder.PrependUint8Slot(0, color, 2) def TestSimpleTableWithEnumEnd(builder): return builder.EndObject() @@ -708,16 +708,16 @@ class Stat(object): return 0 def StatStart(builder): - return builder.StartObject(3) + builder.StartObject(3) def StatAddId(builder, id): - return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(id), 0) + builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(id), 0) def StatAddVal(builder, val): - return builder.PrependInt64Slot(1, val, 0) + builder.PrependInt64Slot(1, val, 0) def StatAddCount(builder, count): - return builder.PrependUint16Slot(2, count, 0) + builder.PrependUint16Slot(2, count, 0) def StatEnd(builder): return builder.EndObject() @@ -800,10 +800,10 @@ class Referrable(object): return 0 def ReferrableStart(builder): - return builder.StartObject(1) + builder.StartObject(1) def ReferrableAddId(builder, id): - return builder.PrependUint64Slot(0, id, 0) + builder.PrependUint64Slot(0, id, 0) def ReferrableEnd(builder): return builder.EndObject() @@ -1050,7 +1050,7 @@ class Monster(object): def TestnestedflatbufferNestedRoot(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(30)) if o != 0: - from MyGame.Example.Monster import Monster + from .MyGame.Example.Monster import Monster return Monster.GetRootAs(self._tab.Bytes, self._tab.Vector(o)) return 0 @@ -1581,7 +1581,7 @@ class Monster(object): def TestrequirednestedflatbufferNestedRoot(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(102)) if o != 0: - from MyGame.Example.Monster import Monster + from .MyGame.Example.Monster import Monster return Monster.GetRootAs(self._tab.Bytes, self._tab.Vector(o)) return 0 @@ -1702,58 +1702,58 @@ class Monster(object): return float('inf') def MonsterStart(builder): - return builder.StartObject(62) + builder.StartObject(62) def MonsterAddPos(builder, pos): - return builder.PrependStructSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(pos), 0) + builder.PrependStructSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(pos), 0) def MonsterAddMana(builder, mana): - return builder.PrependInt16Slot(1, mana, 150) + builder.PrependInt16Slot(1, mana, 150) def MonsterAddHp(builder, hp): - return builder.PrependInt16Slot(2, hp, 100) + builder.PrependInt16Slot(2, hp, 100) def MonsterAddName(builder, name): - return builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) def MonsterAddInventory(builder, inventory): - return builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(inventory), 0) + builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(inventory), 0) def MonsterStartInventoryVector(builder, numElems): return builder.StartVector(1, numElems, 1) def MonsterAddColor(builder, color): - return builder.PrependUint8Slot(6, color, 8) + builder.PrependUint8Slot(6, color, 8) def MonsterAddTestType(builder, testType): - return builder.PrependUint8Slot(7, testType, 0) + builder.PrependUint8Slot(7, testType, 0) def MonsterAddTest(builder, test): - return builder.PrependUOffsetTRelativeSlot(8, flatbuffers.number_types.UOffsetTFlags.py_type(test), 0) + builder.PrependUOffsetTRelativeSlot(8, flatbuffers.number_types.UOffsetTFlags.py_type(test), 0) def MonsterAddTest4(builder, test4): - return builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(test4), 0) + builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(test4), 0) def MonsterStartTest4Vector(builder, numElems): return builder.StartVector(4, numElems, 2) def MonsterAddTestarrayofstring(builder, testarrayofstring): - return builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofstring), 0) + builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofstring), 0) def MonsterStartTestarrayofstringVector(builder, numElems): return builder.StartVector(4, numElems, 4) def MonsterAddTestarrayoftables(builder, testarrayoftables): - return builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayoftables), 0) + builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayoftables), 0) def MonsterStartTestarrayoftablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) def MonsterAddEnemy(builder, enemy): - return builder.PrependUOffsetTRelativeSlot(12, flatbuffers.number_types.UOffsetTFlags.py_type(enemy), 0) + builder.PrependUOffsetTRelativeSlot(12, flatbuffers.number_types.UOffsetTFlags.py_type(enemy), 0) def MonsterAddTestnestedflatbuffer(builder, testnestedflatbuffer): - return builder.PrependUOffsetTRelativeSlot(13, flatbuffers.number_types.UOffsetTFlags.py_type(testnestedflatbuffer), 0) + builder.PrependUOffsetTRelativeSlot(13, flatbuffers.number_types.UOffsetTFlags.py_type(testnestedflatbuffer), 0) def MonsterStartTestnestedflatbufferVector(builder, numElems): return builder.StartVector(1, numElems, 1) @@ -1764,151 +1764,151 @@ def MonsterMakeTestnestedflatbufferVectorFromBytes(builder, bytes): builder.Bytes[builder.head : builder.head + len(bytes)] = bytes return builder.EndVector() def MonsterAddTestempty(builder, testempty): - return builder.PrependUOffsetTRelativeSlot(14, flatbuffers.number_types.UOffsetTFlags.py_type(testempty), 0) + builder.PrependUOffsetTRelativeSlot(14, flatbuffers.number_types.UOffsetTFlags.py_type(testempty), 0) def MonsterAddTestbool(builder, testbool): - return builder.PrependBoolSlot(15, testbool, 0) + builder.PrependBoolSlot(15, testbool, 0) def MonsterAddTesthashs32Fnv1(builder, testhashs32Fnv1): - return builder.PrependInt32Slot(16, testhashs32Fnv1, 0) + builder.PrependInt32Slot(16, testhashs32Fnv1, 0) def MonsterAddTesthashu32Fnv1(builder, testhashu32Fnv1): - return builder.PrependUint32Slot(17, testhashu32Fnv1, 0) + builder.PrependUint32Slot(17, testhashu32Fnv1, 0) def MonsterAddTesthashs64Fnv1(builder, testhashs64Fnv1): - return builder.PrependInt64Slot(18, testhashs64Fnv1, 0) + builder.PrependInt64Slot(18, testhashs64Fnv1, 0) def MonsterAddTesthashu64Fnv1(builder, testhashu64Fnv1): - return builder.PrependUint64Slot(19, testhashu64Fnv1, 0) + builder.PrependUint64Slot(19, testhashu64Fnv1, 0) def MonsterAddTesthashs32Fnv1a(builder, testhashs32Fnv1a): - return builder.PrependInt32Slot(20, testhashs32Fnv1a, 0) + builder.PrependInt32Slot(20, testhashs32Fnv1a, 0) def MonsterAddTesthashu32Fnv1a(builder, testhashu32Fnv1a): - return builder.PrependUint32Slot(21, testhashu32Fnv1a, 0) + builder.PrependUint32Slot(21, testhashu32Fnv1a, 0) def MonsterAddTesthashs64Fnv1a(builder, testhashs64Fnv1a): - return builder.PrependInt64Slot(22, testhashs64Fnv1a, 0) + builder.PrependInt64Slot(22, testhashs64Fnv1a, 0) def MonsterAddTesthashu64Fnv1a(builder, testhashu64Fnv1a): - return builder.PrependUint64Slot(23, testhashu64Fnv1a, 0) + builder.PrependUint64Slot(23, testhashu64Fnv1a, 0) def MonsterAddTestarrayofbools(builder, testarrayofbools): - return builder.PrependUOffsetTRelativeSlot(24, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofbools), 0) + builder.PrependUOffsetTRelativeSlot(24, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofbools), 0) def MonsterStartTestarrayofboolsVector(builder, numElems): return builder.StartVector(1, numElems, 1) def MonsterAddTestf(builder, testf): - return builder.PrependFloat32Slot(25, testf, 3.14159) + builder.PrependFloat32Slot(25, testf, 3.14159) def MonsterAddTestf2(builder, testf2): - return builder.PrependFloat32Slot(26, testf2, 3.0) + builder.PrependFloat32Slot(26, testf2, 3.0) def MonsterAddTestf3(builder, testf3): - return builder.PrependFloat32Slot(27, testf3, 0.0) + builder.PrependFloat32Slot(27, testf3, 0.0) def MonsterAddTestarrayofstring2(builder, testarrayofstring2): - return builder.PrependUOffsetTRelativeSlot(28, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofstring2), 0) + builder.PrependUOffsetTRelativeSlot(28, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofstring2), 0) def MonsterStartTestarrayofstring2Vector(builder, numElems): return builder.StartVector(4, numElems, 4) def MonsterAddTestarrayofsortedstruct(builder, testarrayofsortedstruct): - return builder.PrependUOffsetTRelativeSlot(29, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofsortedstruct), 0) + builder.PrependUOffsetTRelativeSlot(29, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofsortedstruct), 0) def MonsterStartTestarrayofsortedstructVector(builder, numElems): return builder.StartVector(8, numElems, 4) def MonsterAddFlex(builder, flex): - return builder.PrependUOffsetTRelativeSlot(30, flatbuffers.number_types.UOffsetTFlags.py_type(flex), 0) + builder.PrependUOffsetTRelativeSlot(30, flatbuffers.number_types.UOffsetTFlags.py_type(flex), 0) def MonsterStartFlexVector(builder, numElems): return builder.StartVector(1, numElems, 1) def MonsterAddTest5(builder, test5): - return builder.PrependUOffsetTRelativeSlot(31, flatbuffers.number_types.UOffsetTFlags.py_type(test5), 0) + builder.PrependUOffsetTRelativeSlot(31, flatbuffers.number_types.UOffsetTFlags.py_type(test5), 0) def MonsterStartTest5Vector(builder, numElems): return builder.StartVector(4, numElems, 2) def MonsterAddVectorOfLongs(builder, vectorOfLongs): - return builder.PrependUOffsetTRelativeSlot(32, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfLongs), 0) + builder.PrependUOffsetTRelativeSlot(32, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfLongs), 0) def MonsterStartVectorOfLongsVector(builder, numElems): return builder.StartVector(8, numElems, 8) def MonsterAddVectorOfDoubles(builder, vectorOfDoubles): - return builder.PrependUOffsetTRelativeSlot(33, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfDoubles), 0) + builder.PrependUOffsetTRelativeSlot(33, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfDoubles), 0) def MonsterStartVectorOfDoublesVector(builder, numElems): return builder.StartVector(8, numElems, 8) def MonsterAddParentNamespaceTest(builder, parentNamespaceTest): - return builder.PrependUOffsetTRelativeSlot(34, flatbuffers.number_types.UOffsetTFlags.py_type(parentNamespaceTest), 0) + builder.PrependUOffsetTRelativeSlot(34, flatbuffers.number_types.UOffsetTFlags.py_type(parentNamespaceTest), 0) def MonsterAddVectorOfReferrables(builder, vectorOfReferrables): - return builder.PrependUOffsetTRelativeSlot(35, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfReferrables), 0) + builder.PrependUOffsetTRelativeSlot(35, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfReferrables), 0) def MonsterStartVectorOfReferrablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) def MonsterAddSingleWeakReference(builder, singleWeakReference): - return builder.PrependUint64Slot(36, singleWeakReference, 0) + builder.PrependUint64Slot(36, singleWeakReference, 0) def MonsterAddVectorOfWeakReferences(builder, vectorOfWeakReferences): - return builder.PrependUOffsetTRelativeSlot(37, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfWeakReferences), 0) + builder.PrependUOffsetTRelativeSlot(37, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfWeakReferences), 0) def MonsterStartVectorOfWeakReferencesVector(builder, numElems): return builder.StartVector(8, numElems, 8) def MonsterAddVectorOfStrongReferrables(builder, vectorOfStrongReferrables): - return builder.PrependUOffsetTRelativeSlot(38, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfStrongReferrables), 0) + builder.PrependUOffsetTRelativeSlot(38, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfStrongReferrables), 0) def MonsterStartVectorOfStrongReferrablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) def MonsterAddCoOwningReference(builder, coOwningReference): - return builder.PrependUint64Slot(39, coOwningReference, 0) + builder.PrependUint64Slot(39, coOwningReference, 0) def MonsterAddVectorOfCoOwningReferences(builder, vectorOfCoOwningReferences): - return builder.PrependUOffsetTRelativeSlot(40, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfCoOwningReferences), 0) + builder.PrependUOffsetTRelativeSlot(40, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfCoOwningReferences), 0) def MonsterStartVectorOfCoOwningReferencesVector(builder, numElems): return builder.StartVector(8, numElems, 8) def MonsterAddNonOwningReference(builder, nonOwningReference): - return builder.PrependUint64Slot(41, nonOwningReference, 0) + builder.PrependUint64Slot(41, nonOwningReference, 0) def MonsterAddVectorOfNonOwningReferences(builder, vectorOfNonOwningReferences): - return builder.PrependUOffsetTRelativeSlot(42, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfNonOwningReferences), 0) + builder.PrependUOffsetTRelativeSlot(42, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfNonOwningReferences), 0) def MonsterStartVectorOfNonOwningReferencesVector(builder, numElems): return builder.StartVector(8, numElems, 8) def MonsterAddAnyUniqueType(builder, anyUniqueType): - return builder.PrependUint8Slot(43, anyUniqueType, 0) + builder.PrependUint8Slot(43, anyUniqueType, 0) def MonsterAddAnyUnique(builder, anyUnique): - return builder.PrependUOffsetTRelativeSlot(44, flatbuffers.number_types.UOffsetTFlags.py_type(anyUnique), 0) + builder.PrependUOffsetTRelativeSlot(44, flatbuffers.number_types.UOffsetTFlags.py_type(anyUnique), 0) def MonsterAddAnyAmbiguousType(builder, anyAmbiguousType): - return builder.PrependUint8Slot(45, anyAmbiguousType, 0) + builder.PrependUint8Slot(45, anyAmbiguousType, 0) def MonsterAddAnyAmbiguous(builder, anyAmbiguous): - return builder.PrependUOffsetTRelativeSlot(46, flatbuffers.number_types.UOffsetTFlags.py_type(anyAmbiguous), 0) + builder.PrependUOffsetTRelativeSlot(46, flatbuffers.number_types.UOffsetTFlags.py_type(anyAmbiguous), 0) def MonsterAddVectorOfEnums(builder, vectorOfEnums): - return builder.PrependUOffsetTRelativeSlot(47, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfEnums), 0) + builder.PrependUOffsetTRelativeSlot(47, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfEnums), 0) def MonsterStartVectorOfEnumsVector(builder, numElems): return builder.StartVector(1, numElems, 1) def MonsterAddSignedEnum(builder, signedEnum): - return builder.PrependInt8Slot(48, signedEnum, -1) + builder.PrependInt8Slot(48, signedEnum, -1) def MonsterAddTestrequirednestedflatbuffer(builder, testrequirednestedflatbuffer): - return builder.PrependUOffsetTRelativeSlot(49, flatbuffers.number_types.UOffsetTFlags.py_type(testrequirednestedflatbuffer), 0) + builder.PrependUOffsetTRelativeSlot(49, flatbuffers.number_types.UOffsetTFlags.py_type(testrequirednestedflatbuffer), 0) def MonsterStartTestrequirednestedflatbufferVector(builder, numElems): return builder.StartVector(1, numElems, 1) @@ -1919,43 +1919,43 @@ def MonsterMakeTestrequirednestedflatbufferVectorFromBytes(builder, bytes): builder.Bytes[builder.head : builder.head + len(bytes)] = bytes return builder.EndVector() def MonsterAddScalarKeySortedTables(builder, scalarKeySortedTables): - return builder.PrependUOffsetTRelativeSlot(50, flatbuffers.number_types.UOffsetTFlags.py_type(scalarKeySortedTables), 0) + builder.PrependUOffsetTRelativeSlot(50, flatbuffers.number_types.UOffsetTFlags.py_type(scalarKeySortedTables), 0) def MonsterStartScalarKeySortedTablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) def MonsterAddNativeInline(builder, nativeInline): - return builder.PrependStructSlot(51, flatbuffers.number_types.UOffsetTFlags.py_type(nativeInline), 0) + builder.PrependStructSlot(51, flatbuffers.number_types.UOffsetTFlags.py_type(nativeInline), 0) def MonsterAddLongEnumNonEnumDefault(builder, longEnumNonEnumDefault): - return builder.PrependUint64Slot(52, longEnumNonEnumDefault, 0) + builder.PrependUint64Slot(52, longEnumNonEnumDefault, 0) def MonsterAddLongEnumNormalDefault(builder, longEnumNormalDefault): - return builder.PrependUint64Slot(53, longEnumNormalDefault, 2) + builder.PrependUint64Slot(53, longEnumNormalDefault, 2) def MonsterAddNanDefault(builder, nanDefault): - return builder.PrependFloat32Slot(54, nanDefault, float('nan')) + builder.PrependFloat32Slot(54, nanDefault, float('nan')) def MonsterAddInfDefault(builder, infDefault): - return builder.PrependFloat32Slot(55, infDefault, float('inf')) + builder.PrependFloat32Slot(55, infDefault, float('inf')) def MonsterAddPositiveInfDefault(builder, positiveInfDefault): - return builder.PrependFloat32Slot(56, positiveInfDefault, float('inf')) + builder.PrependFloat32Slot(56, positiveInfDefault, float('inf')) def MonsterAddInfinityDefault(builder, infinityDefault): - return builder.PrependFloat32Slot(57, infinityDefault, float('inf')) + builder.PrependFloat32Slot(57, infinityDefault, float('inf')) def MonsterAddPositiveInfinityDefault(builder, positiveInfinityDefault): - return builder.PrependFloat32Slot(58, positiveInfinityDefault, float('inf')) + builder.PrependFloat32Slot(58, positiveInfinityDefault, float('inf')) def MonsterAddNegativeInfDefault(builder, negativeInfDefault): - return builder.PrependFloat32Slot(59, negativeInfDefault, float('-inf')) + builder.PrependFloat32Slot(59, negativeInfDefault, float('-inf')) def MonsterAddNegativeInfinityDefault(builder, negativeInfinityDefault): - return builder.PrependFloat32Slot(60, negativeInfinityDefault, float('-inf')) + builder.PrependFloat32Slot(60, negativeInfinityDefault, float('-inf')) def MonsterAddDoubleInfDefault(builder, doubleInfDefault): - return builder.PrependFloat64Slot(61, doubleInfDefault, float('inf')) + builder.PrependFloat64Slot(61, doubleInfDefault, float('inf')) def MonsterEnd(builder): return builder.EndObject() @@ -2652,46 +2652,46 @@ class TypeAliases(object): return o == 0 def TypeAliasesStart(builder): - return builder.StartObject(12) + builder.StartObject(12) def TypeAliasesAddI8(builder, i8): - return builder.PrependInt8Slot(0, i8, 0) + builder.PrependInt8Slot(0, i8, 0) def TypeAliasesAddU8(builder, u8): - return builder.PrependUint8Slot(1, u8, 0) + builder.PrependUint8Slot(1, u8, 0) def TypeAliasesAddI16(builder, i16): - return builder.PrependInt16Slot(2, i16, 0) + builder.PrependInt16Slot(2, i16, 0) def TypeAliasesAddU16(builder, u16): - return builder.PrependUint16Slot(3, u16, 0) + builder.PrependUint16Slot(3, u16, 0) def TypeAliasesAddI32(builder, i32): - return builder.PrependInt32Slot(4, i32, 0) + builder.PrependInt32Slot(4, i32, 0) def TypeAliasesAddU32(builder, u32): - return builder.PrependUint32Slot(5, u32, 0) + builder.PrependUint32Slot(5, u32, 0) def TypeAliasesAddI64(builder, i64): - return builder.PrependInt64Slot(6, i64, 0) + builder.PrependInt64Slot(6, i64, 0) def TypeAliasesAddU64(builder, u64): - return builder.PrependUint64Slot(7, u64, 0) + builder.PrependUint64Slot(7, u64, 0) def TypeAliasesAddF32(builder, f32): - return builder.PrependFloat32Slot(8, f32, 0.0) + builder.PrependFloat32Slot(8, f32, 0.0) def TypeAliasesAddF64(builder, f64): - return builder.PrependFloat64Slot(9, f64, 0.0) + builder.PrependFloat64Slot(9, f64, 0.0) def TypeAliasesAddV8(builder, v8): - return builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(v8), 0) + builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(v8), 0) def TypeAliasesStartV8Vector(builder, numElems): return builder.StartVector(1, numElems, 1) def TypeAliasesAddVf64(builder, vf64): - return builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(vf64), 0) + builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(vf64), 0) def TypeAliasesStartVf64Vector(builder, numElems): return builder.StartVector(8, numElems, 8) diff --git a/tests/optional_scalars/ScalarStuff.py b/tests/optional_scalars/ScalarStuff.py index b75ba22d..07737d29 100644 --- a/tests/optional_scalars/ScalarStuff.py +++ b/tests/optional_scalars/ScalarStuff.py @@ -281,226 +281,226 @@ class ScalarStuff(object): return 1 def ScalarStuffStart(builder): - return builder.StartObject(36) + builder.StartObject(36) def Start(builder): - return ScalarStuffStart(builder) + ScalarStuffStart(builder) def ScalarStuffAddJustI8(builder, justI8): - return builder.PrependInt8Slot(0, justI8, 0) + builder.PrependInt8Slot(0, justI8, 0) -def AddJustI8(builder, justI8): - return ScalarStuffAddJustI8(builder, justI8) +def AddJustI8(builder: flatbuffers.Builder, justI8: int): + ScalarStuffAddJustI8(builder, justI8) def ScalarStuffAddMaybeI8(builder, maybeI8): - return builder.PrependInt8Slot(1, maybeI8, None) + builder.PrependInt8Slot(1, maybeI8, None) -def AddMaybeI8(builder, maybeI8): - return ScalarStuffAddMaybeI8(builder, maybeI8) +def AddMaybeI8(builder: flatbuffers.Builder, maybeI8: int): + ScalarStuffAddMaybeI8(builder, maybeI8) def ScalarStuffAddDefaultI8(builder, defaultI8): - return builder.PrependInt8Slot(2, defaultI8, 42) + builder.PrependInt8Slot(2, defaultI8, 42) -def AddDefaultI8(builder, defaultI8): - return ScalarStuffAddDefaultI8(builder, defaultI8) +def AddDefaultI8(builder: flatbuffers.Builder, defaultI8: int): + ScalarStuffAddDefaultI8(builder, defaultI8) def ScalarStuffAddJustU8(builder, justU8): - return builder.PrependUint8Slot(3, justU8, 0) + builder.PrependUint8Slot(3, justU8, 0) -def AddJustU8(builder, justU8): - return ScalarStuffAddJustU8(builder, justU8) +def AddJustU8(builder: flatbuffers.Builder, justU8: int): + ScalarStuffAddJustU8(builder, justU8) def ScalarStuffAddMaybeU8(builder, maybeU8): - return builder.PrependUint8Slot(4, maybeU8, None) + builder.PrependUint8Slot(4, maybeU8, None) -def AddMaybeU8(builder, maybeU8): - return ScalarStuffAddMaybeU8(builder, maybeU8) +def AddMaybeU8(builder: flatbuffers.Builder, maybeU8: int): + ScalarStuffAddMaybeU8(builder, maybeU8) def ScalarStuffAddDefaultU8(builder, defaultU8): - return builder.PrependUint8Slot(5, defaultU8, 42) + builder.PrependUint8Slot(5, defaultU8, 42) -def AddDefaultU8(builder, defaultU8): - return ScalarStuffAddDefaultU8(builder, defaultU8) +def AddDefaultU8(builder: flatbuffers.Builder, defaultU8: int): + ScalarStuffAddDefaultU8(builder, defaultU8) def ScalarStuffAddJustI16(builder, justI16): - return builder.PrependInt16Slot(6, justI16, 0) + builder.PrependInt16Slot(6, justI16, 0) -def AddJustI16(builder, justI16): - return ScalarStuffAddJustI16(builder, justI16) +def AddJustI16(builder: flatbuffers.Builder, justI16: int): + ScalarStuffAddJustI16(builder, justI16) def ScalarStuffAddMaybeI16(builder, maybeI16): - return builder.PrependInt16Slot(7, maybeI16, None) + builder.PrependInt16Slot(7, maybeI16, None) -def AddMaybeI16(builder, maybeI16): - return ScalarStuffAddMaybeI16(builder, maybeI16) +def AddMaybeI16(builder: flatbuffers.Builder, maybeI16: int): + ScalarStuffAddMaybeI16(builder, maybeI16) def ScalarStuffAddDefaultI16(builder, defaultI16): - return builder.PrependInt16Slot(8, defaultI16, 42) + builder.PrependInt16Slot(8, defaultI16, 42) -def AddDefaultI16(builder, defaultI16): - return ScalarStuffAddDefaultI16(builder, defaultI16) +def AddDefaultI16(builder: flatbuffers.Builder, defaultI16: int): + ScalarStuffAddDefaultI16(builder, defaultI16) def ScalarStuffAddJustU16(builder, justU16): - return builder.PrependUint16Slot(9, justU16, 0) + builder.PrependUint16Slot(9, justU16, 0) -def AddJustU16(builder, justU16): - return ScalarStuffAddJustU16(builder, justU16) +def AddJustU16(builder: flatbuffers.Builder, justU16: int): + ScalarStuffAddJustU16(builder, justU16) def ScalarStuffAddMaybeU16(builder, maybeU16): - return builder.PrependUint16Slot(10, maybeU16, None) + builder.PrependUint16Slot(10, maybeU16, None) -def AddMaybeU16(builder, maybeU16): - return ScalarStuffAddMaybeU16(builder, maybeU16) +def AddMaybeU16(builder: flatbuffers.Builder, maybeU16: int): + ScalarStuffAddMaybeU16(builder, maybeU16) def ScalarStuffAddDefaultU16(builder, defaultU16): - return builder.PrependUint16Slot(11, defaultU16, 42) + builder.PrependUint16Slot(11, defaultU16, 42) -def AddDefaultU16(builder, defaultU16): - return ScalarStuffAddDefaultU16(builder, defaultU16) +def AddDefaultU16(builder: flatbuffers.Builder, defaultU16: int): + ScalarStuffAddDefaultU16(builder, defaultU16) def ScalarStuffAddJustI32(builder, justI32): - return builder.PrependInt32Slot(12, justI32, 0) + builder.PrependInt32Slot(12, justI32, 0) -def AddJustI32(builder, justI32): - return ScalarStuffAddJustI32(builder, justI32) +def AddJustI32(builder: flatbuffers.Builder, justI32: int): + ScalarStuffAddJustI32(builder, justI32) def ScalarStuffAddMaybeI32(builder, maybeI32): - return builder.PrependInt32Slot(13, maybeI32, None) + builder.PrependInt32Slot(13, maybeI32, None) -def AddMaybeI32(builder, maybeI32): - return ScalarStuffAddMaybeI32(builder, maybeI32) +def AddMaybeI32(builder: flatbuffers.Builder, maybeI32: int): + ScalarStuffAddMaybeI32(builder, maybeI32) def ScalarStuffAddDefaultI32(builder, defaultI32): - return builder.PrependInt32Slot(14, defaultI32, 42) + builder.PrependInt32Slot(14, defaultI32, 42) -def AddDefaultI32(builder, defaultI32): - return ScalarStuffAddDefaultI32(builder, defaultI32) +def AddDefaultI32(builder: flatbuffers.Builder, defaultI32: int): + ScalarStuffAddDefaultI32(builder, defaultI32) def ScalarStuffAddJustU32(builder, justU32): - return builder.PrependUint32Slot(15, justU32, 0) + builder.PrependUint32Slot(15, justU32, 0) -def AddJustU32(builder, justU32): - return ScalarStuffAddJustU32(builder, justU32) +def AddJustU32(builder: flatbuffers.Builder, justU32: int): + ScalarStuffAddJustU32(builder, justU32) def ScalarStuffAddMaybeU32(builder, maybeU32): - return builder.PrependUint32Slot(16, maybeU32, None) + builder.PrependUint32Slot(16, maybeU32, None) -def AddMaybeU32(builder, maybeU32): - return ScalarStuffAddMaybeU32(builder, maybeU32) +def AddMaybeU32(builder: flatbuffers.Builder, maybeU32: int): + ScalarStuffAddMaybeU32(builder, maybeU32) def ScalarStuffAddDefaultU32(builder, defaultU32): - return builder.PrependUint32Slot(17, defaultU32, 42) + builder.PrependUint32Slot(17, defaultU32, 42) -def AddDefaultU32(builder, defaultU32): - return ScalarStuffAddDefaultU32(builder, defaultU32) +def AddDefaultU32(builder: flatbuffers.Builder, defaultU32: int): + ScalarStuffAddDefaultU32(builder, defaultU32) def ScalarStuffAddJustI64(builder, justI64): - return builder.PrependInt64Slot(18, justI64, 0) + builder.PrependInt64Slot(18, justI64, 0) -def AddJustI64(builder, justI64): - return ScalarStuffAddJustI64(builder, justI64) +def AddJustI64(builder: flatbuffers.Builder, justI64: int): + ScalarStuffAddJustI64(builder, justI64) def ScalarStuffAddMaybeI64(builder, maybeI64): - return builder.PrependInt64Slot(19, maybeI64, None) + builder.PrependInt64Slot(19, maybeI64, None) -def AddMaybeI64(builder, maybeI64): - return ScalarStuffAddMaybeI64(builder, maybeI64) +def AddMaybeI64(builder: flatbuffers.Builder, maybeI64: int): + ScalarStuffAddMaybeI64(builder, maybeI64) def ScalarStuffAddDefaultI64(builder, defaultI64): - return builder.PrependInt64Slot(20, defaultI64, 42) + builder.PrependInt64Slot(20, defaultI64, 42) -def AddDefaultI64(builder, defaultI64): - return ScalarStuffAddDefaultI64(builder, defaultI64) +def AddDefaultI64(builder: flatbuffers.Builder, defaultI64: int): + ScalarStuffAddDefaultI64(builder, defaultI64) def ScalarStuffAddJustU64(builder, justU64): - return builder.PrependUint64Slot(21, justU64, 0) + builder.PrependUint64Slot(21, justU64, 0) -def AddJustU64(builder, justU64): - return ScalarStuffAddJustU64(builder, justU64) +def AddJustU64(builder: flatbuffers.Builder, justU64: int): + ScalarStuffAddJustU64(builder, justU64) def ScalarStuffAddMaybeU64(builder, maybeU64): - return builder.PrependUint64Slot(22, maybeU64, None) + builder.PrependUint64Slot(22, maybeU64, None) -def AddMaybeU64(builder, maybeU64): - return ScalarStuffAddMaybeU64(builder, maybeU64) +def AddMaybeU64(builder: flatbuffers.Builder, maybeU64: int): + ScalarStuffAddMaybeU64(builder, maybeU64) def ScalarStuffAddDefaultU64(builder, defaultU64): - return builder.PrependUint64Slot(23, defaultU64, 42) + builder.PrependUint64Slot(23, defaultU64, 42) -def AddDefaultU64(builder, defaultU64): - return ScalarStuffAddDefaultU64(builder, defaultU64) +def AddDefaultU64(builder: flatbuffers.Builder, defaultU64: int): + ScalarStuffAddDefaultU64(builder, defaultU64) def ScalarStuffAddJustF32(builder, justF32): - return builder.PrependFloat32Slot(24, justF32, 0.0) + builder.PrependFloat32Slot(24, justF32, 0.0) -def AddJustF32(builder, justF32): - return ScalarStuffAddJustF32(builder, justF32) +def AddJustF32(builder: flatbuffers.Builder, justF32: float): + ScalarStuffAddJustF32(builder, justF32) def ScalarStuffAddMaybeF32(builder, maybeF32): - return builder.PrependFloat32Slot(25, maybeF32, None) + builder.PrependFloat32Slot(25, maybeF32, None) -def AddMaybeF32(builder, maybeF32): - return ScalarStuffAddMaybeF32(builder, maybeF32) +def AddMaybeF32(builder: flatbuffers.Builder, maybeF32: float): + ScalarStuffAddMaybeF32(builder, maybeF32) def ScalarStuffAddDefaultF32(builder, defaultF32): - return builder.PrependFloat32Slot(26, defaultF32, 42.0) + builder.PrependFloat32Slot(26, defaultF32, 42.0) -def AddDefaultF32(builder, defaultF32): - return ScalarStuffAddDefaultF32(builder, defaultF32) +def AddDefaultF32(builder: flatbuffers.Builder, defaultF32: float): + ScalarStuffAddDefaultF32(builder, defaultF32) def ScalarStuffAddJustF64(builder, justF64): - return builder.PrependFloat64Slot(27, justF64, 0.0) + builder.PrependFloat64Slot(27, justF64, 0.0) -def AddJustF64(builder, justF64): - return ScalarStuffAddJustF64(builder, justF64) +def AddJustF64(builder: flatbuffers.Builder, justF64: float): + ScalarStuffAddJustF64(builder, justF64) def ScalarStuffAddMaybeF64(builder, maybeF64): - return builder.PrependFloat64Slot(28, maybeF64, None) + builder.PrependFloat64Slot(28, maybeF64, None) -def AddMaybeF64(builder, maybeF64): - return ScalarStuffAddMaybeF64(builder, maybeF64) +def AddMaybeF64(builder: flatbuffers.Builder, maybeF64: float): + ScalarStuffAddMaybeF64(builder, maybeF64) def ScalarStuffAddDefaultF64(builder, defaultF64): - return builder.PrependFloat64Slot(29, defaultF64, 42.0) + builder.PrependFloat64Slot(29, defaultF64, 42.0) -def AddDefaultF64(builder, defaultF64): - return ScalarStuffAddDefaultF64(builder, defaultF64) +def AddDefaultF64(builder: flatbuffers.Builder, defaultF64: float): + ScalarStuffAddDefaultF64(builder, defaultF64) def ScalarStuffAddJustBool(builder, justBool): - return builder.PrependBoolSlot(30, justBool, 0) + builder.PrependBoolSlot(30, justBool, 0) -def AddJustBool(builder, justBool): - return ScalarStuffAddJustBool(builder, justBool) +def AddJustBool(builder: flatbuffers.Builder, justBool: bool): + ScalarStuffAddJustBool(builder, justBool) def ScalarStuffAddMaybeBool(builder, maybeBool): - return builder.PrependBoolSlot(31, maybeBool, None) + builder.PrependBoolSlot(31, maybeBool, None) -def AddMaybeBool(builder, maybeBool): - return ScalarStuffAddMaybeBool(builder, maybeBool) +def AddMaybeBool(builder: flatbuffers.Builder, maybeBool: bool): + ScalarStuffAddMaybeBool(builder, maybeBool) def ScalarStuffAddDefaultBool(builder, defaultBool): - return builder.PrependBoolSlot(32, defaultBool, 1) + builder.PrependBoolSlot(32, defaultBool, 1) -def AddDefaultBool(builder, defaultBool): - return ScalarStuffAddDefaultBool(builder, defaultBool) +def AddDefaultBool(builder: flatbuffers.Builder, defaultBool: bool): + ScalarStuffAddDefaultBool(builder, defaultBool) def ScalarStuffAddJustEnum(builder, justEnum): - return builder.PrependInt8Slot(33, justEnum, 0) + builder.PrependInt8Slot(33, justEnum, 0) -def AddJustEnum(builder, justEnum): - return ScalarStuffAddJustEnum(builder, justEnum) +def AddJustEnum(builder: flatbuffers.Builder, justEnum: int): + ScalarStuffAddJustEnum(builder, justEnum) def ScalarStuffAddMaybeEnum(builder, maybeEnum): - return builder.PrependInt8Slot(34, maybeEnum, None) + builder.PrependInt8Slot(34, maybeEnum, None) -def AddMaybeEnum(builder, maybeEnum): - return ScalarStuffAddMaybeEnum(builder, maybeEnum) +def AddMaybeEnum(builder: flatbuffers.Builder, maybeEnum: int): + ScalarStuffAddMaybeEnum(builder, maybeEnum) def ScalarStuffAddDefaultEnum(builder, defaultEnum): - return builder.PrependInt8Slot(35, defaultEnum, 1) + builder.PrependInt8Slot(35, defaultEnum, 1) -def AddDefaultEnum(builder, defaultEnum): - return ScalarStuffAddDefaultEnum(builder, defaultEnum) +def AddDefaultEnum(builder: flatbuffers.Builder, defaultEnum: int): + ScalarStuffAddDefaultEnum(builder, defaultEnum) def ScalarStuffEnd(builder): return builder.EndObject() diff --git a/tests/test.fbs b/tests/test.fbs new file mode 100644 index 00000000..791f7f7b --- /dev/null +++ b/tests/test.fbs @@ -0,0 +1,85 @@ +// Generated from test.proto + +include "imported.fbs"; + +namespace proto.test; + +/// Enum doc comment. +enum ProtoEnum : int { + NUL = 0, + FOO = 1, + /// Enum 2nd value doc comment misaligned. + BAR = 5, +} + +namespace proto.test.ProtoMessage_.OtherMessage_; + +enum ProtoEnum : int { + NUL = 0, + FOO = 1, + BAR = 2, + BAZ = 3, +} + +namespace proto.test; + +/// 2nd table doc comment with +/// many lines. +table ProtoMessage { + c:int = 16; + d:long; + p:uint; + e:ulong; + /// doc comment for f. + f:int = -1; + g:long; + h:uint; + q:ulong; + i:int; + j:long; + /// doc comment for k. + k:bool; + /// doc comment for l on 2 + /// lines + l:string (required); + m:[ubyte]; + n:proto.test.ProtoMessage_.OtherMessage; + o:[string]; + z:proto.test.ImportedMessage; + /// doc comment for r. + r:proto.test.ProtoMessage_.Anonymous0; + outer_enum:proto.test.ProtoEnum; + u:float = +inf; + v:float = +inf; + w:float = -inf; + grades:[proto.test.ProtoMessage_.GradesEntry]; + other_message_map:[proto.test.ProtoMessage_.OtherMessageMapEntry]; +} + +namespace proto.test.ProtoMessage_; + +table OtherMessage { + a:double; + /// doc comment for b. + b:float = 3.14149; + foo_bar_baz:proto.test.ProtoMessage_.OtherMessage_.ProtoEnum; +} + +table Anonymous0 { + /// doc comment for s. + s:proto.test.ImportedMessage; + /// doc comment for t on 2 + /// lines. + t:proto.test.ProtoMessage_.OtherMessage; +} + +table GradesEntry { + key:string (key); + value:float; +} + +table OtherMessageMapEntry { + key:string (key); + value:proto.test.ProtoMessage_.OtherMessage; +} + |