diff --git a/python/flatbuffers/reflection/Enum.py b/python/flatbuffers/reflection/Enum.py index 2d484c0b10f..2c366d1cba6 100644 --- a/python/flatbuffers/reflection/Enum.py +++ b/python/flatbuffers/reflection/Enum.py @@ -152,7 +152,7 @@ def AddValues(builder, values): def EnumStartValuesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartValuesVector(builder, numElems: int) -> int: +def StartValuesVector(builder, numElems): return EnumStartValuesVector(builder, numElems) def EnumAddIsUnion(builder, isUnion): @@ -176,7 +176,7 @@ def AddAttributes(builder, attributes): def EnumStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartAttributesVector(builder, numElems: int) -> int: +def StartAttributesVector(builder, numElems): return EnumStartAttributesVector(builder, numElems) def EnumAddDocumentation(builder, documentation): @@ -188,7 +188,7 @@ def AddDocumentation(builder, documentation): def EnumStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartDocumentationVector(builder, numElems: int) -> int: +def StartDocumentationVector(builder, numElems): return EnumStartDocumentationVector(builder, numElems) def EnumAddDeclarationFile(builder, declarationFile): diff --git a/python/flatbuffers/reflection/EnumVal.py b/python/flatbuffers/reflection/EnumVal.py index 3da936b4ac8..3789a16e4c2 100644 --- a/python/flatbuffers/reflection/EnumVal.py +++ b/python/flatbuffers/reflection/EnumVal.py @@ -131,7 +131,7 @@ def AddDocumentation(builder, documentation): def EnumValStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartDocumentationVector(builder, numElems: int) -> int: +def StartDocumentationVector(builder, numElems): return EnumValStartDocumentationVector(builder, numElems) def EnumValAddAttributes(builder, attributes): @@ -143,7 +143,7 @@ def AddAttributes(builder, attributes): def EnumValStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartAttributesVector(builder, numElems: int) -> int: +def StartAttributesVector(builder, numElems): return EnumValStartAttributesVector(builder, numElems) def EnumValEnd(builder): diff --git a/python/flatbuffers/reflection/Field.py b/python/flatbuffers/reflection/Field.py index eb70891ace1..2cce39203bc 100644 --- a/python/flatbuffers/reflection/Field.py +++ b/python/flatbuffers/reflection/Field.py @@ -232,7 +232,7 @@ def AddAttributes(builder, attributes): def FieldStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartAttributesVector(builder, numElems: int) -> int: +def StartAttributesVector(builder, numElems): return FieldStartAttributesVector(builder, numElems) def FieldAddDocumentation(builder, documentation): @@ -244,7 +244,7 @@ def AddDocumentation(builder, documentation): def FieldStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartDocumentationVector(builder, numElems: int) -> int: +def StartDocumentationVector(builder, numElems): return FieldStartDocumentationVector(builder, numElems) def FieldAddOptional(builder, optional): diff --git a/python/flatbuffers/reflection/Object.py b/python/flatbuffers/reflection/Object.py index 33b05733650..41fbc09aba6 100644 --- a/python/flatbuffers/reflection/Object.py +++ b/python/flatbuffers/reflection/Object.py @@ -155,7 +155,7 @@ def AddFields(builder, fields): def ObjectStartFieldsVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartFieldsVector(builder, numElems: int) -> int: +def StartFieldsVector(builder, numElems): return ObjectStartFieldsVector(builder, numElems) def ObjectAddIsStruct(builder, isStruct): @@ -185,7 +185,7 @@ def AddAttributes(builder, attributes): def ObjectStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartAttributesVector(builder, numElems: int) -> int: +def StartAttributesVector(builder, numElems): return ObjectStartAttributesVector(builder, numElems) def ObjectAddDocumentation(builder, documentation): @@ -197,7 +197,7 @@ def AddDocumentation(builder, documentation): def ObjectStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartDocumentationVector(builder, numElems: int) -> int: +def StartDocumentationVector(builder, numElems): return ObjectStartDocumentationVector(builder, numElems) def ObjectAddDeclarationFile(builder, declarationFile): diff --git a/python/flatbuffers/reflection/RPCCall.py b/python/flatbuffers/reflection/RPCCall.py index 3fd7ff8465f..b88c64b776e 100644 --- a/python/flatbuffers/reflection/RPCCall.py +++ b/python/flatbuffers/reflection/RPCCall.py @@ -135,7 +135,7 @@ def AddAttributes(builder, attributes): def RPCCallStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartAttributesVector(builder, numElems: int) -> int: +def StartAttributesVector(builder, numElems): return RPCCallStartAttributesVector(builder, numElems) def RPCCallAddDocumentation(builder, documentation): @@ -147,7 +147,7 @@ def AddDocumentation(builder, documentation): def RPCCallStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartDocumentationVector(builder, numElems: int) -> int: +def StartDocumentationVector(builder, numElems): return RPCCallStartDocumentationVector(builder, numElems) def RPCCallEnd(builder): diff --git a/python/flatbuffers/reflection/Schema.py b/python/flatbuffers/reflection/Schema.py index 61ebb196e5e..357e6ea0e02 100644 --- a/python/flatbuffers/reflection/Schema.py +++ b/python/flatbuffers/reflection/Schema.py @@ -177,7 +177,7 @@ def AddObjects(builder, objects): def SchemaStartObjectsVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartObjectsVector(builder, numElems: int) -> int: +def StartObjectsVector(builder, numElems): return SchemaStartObjectsVector(builder, numElems) def SchemaAddEnums(builder, enums): @@ -189,7 +189,7 @@ def AddEnums(builder, enums): def SchemaStartEnumsVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartEnumsVector(builder, numElems: int) -> int: +def StartEnumsVector(builder, numElems): return SchemaStartEnumsVector(builder, numElems) def SchemaAddFileIdent(builder, fileIdent): @@ -219,7 +219,7 @@ def AddServices(builder, services): def SchemaStartServicesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartServicesVector(builder, numElems: int) -> int: +def StartServicesVector(builder, numElems): return SchemaStartServicesVector(builder, numElems) def SchemaAddAdvancedFeatures(builder, advancedFeatures): @@ -237,7 +237,7 @@ def AddFbsFiles(builder, fbsFiles): def SchemaStartFbsFilesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartFbsFilesVector(builder, numElems: int) -> int: +def StartFbsFilesVector(builder, numElems): return SchemaStartFbsFilesVector(builder, numElems) def SchemaEnd(builder): diff --git a/python/flatbuffers/reflection/SchemaFile.py b/python/flatbuffers/reflection/SchemaFile.py index a81bcd5dbf9..db4e47f1a1a 100644 --- a/python/flatbuffers/reflection/SchemaFile.py +++ b/python/flatbuffers/reflection/SchemaFile.py @@ -81,7 +81,7 @@ def AddIncludedFilenames(builder, includedFilenames): def SchemaFileStartIncludedFilenamesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartIncludedFilenamesVector(builder, numElems: int) -> int: +def StartIncludedFilenamesVector(builder, numElems): return SchemaFileStartIncludedFilenamesVector(builder, numElems) def SchemaFileEnd(builder): diff --git a/python/flatbuffers/reflection/Service.py b/python/flatbuffers/reflection/Service.py index e69e531f551..cbd1b699250 100644 --- a/python/flatbuffers/reflection/Service.py +++ b/python/flatbuffers/reflection/Service.py @@ -134,7 +134,7 @@ def AddCalls(builder, calls): def ServiceStartCallsVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartCallsVector(builder, numElems: int) -> int: +def StartCallsVector(builder, numElems): return ServiceStartCallsVector(builder, numElems) def ServiceAddAttributes(builder, attributes): @@ -146,7 +146,7 @@ def AddAttributes(builder, attributes): def ServiceStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartAttributesVector(builder, numElems: int) -> int: +def StartAttributesVector(builder, numElems): return ServiceStartAttributesVector(builder, numElems) def ServiceAddDocumentation(builder, documentation): @@ -158,7 +158,7 @@ def AddDocumentation(builder, documentation): def ServiceStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartDocumentationVector(builder, numElems: int) -> int: +def StartDocumentationVector(builder, numElems): return ServiceStartDocumentationVector(builder, numElems) def ServiceAddDeclarationFile(builder, declarationFile): diff --git a/src/idl_gen_python.cpp b/src/idl_gen_python.cpp index 279757d0b0a..65ba2303c2b 100644 --- a/src/idl_gen_python.cpp +++ b/src/idl_gen_python.cpp @@ -839,8 +839,12 @@ 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: int) -> int:\n"; + if (parser_.opts.python_typing) { + code += "def Start" + field_method + + "Vector(builder, numElems: int) -> int:\n"; + } else { + code += "def Start" + field_method + "Vector(builder, numElems):\n"; + } code += Indent + "return " + struct_type + "Start"; code += field_method + "Vector(builder, numElems)\n\n"; } diff --git a/tests/MyGame/Example/Monster.py b/tests/MyGame/Example/Monster.py index 1503011fc29..9fb81446efc 100644 --- a/tests/MyGame/Example/Monster.py +++ b/tests/MyGame/Example/Monster.py @@ -911,7 +911,7 @@ def AddInventory(builder, inventory): def MonsterStartInventoryVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def StartInventoryVector(builder, numElems: int) -> int: +def StartInventoryVector(builder, numElems): return MonsterStartInventoryVector(builder, numElems) def MonsterAddColor(builder, color): @@ -941,7 +941,7 @@ def AddTest4(builder, test4): def MonsterStartTest4Vector(builder, numElems): return builder.StartVector(4, numElems, 2) -def StartTest4Vector(builder, numElems: int) -> int: +def StartTest4Vector(builder, numElems): return MonsterStartTest4Vector(builder, numElems) def MonsterAddTestarrayofstring(builder, testarrayofstring): @@ -953,7 +953,7 @@ def AddTestarrayofstring(builder, testarrayofstring): def MonsterStartTestarrayofstringVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartTestarrayofstringVector(builder, numElems: int) -> int: +def StartTestarrayofstringVector(builder, numElems): return MonsterStartTestarrayofstringVector(builder, numElems) def MonsterAddTestarrayoftables(builder, testarrayoftables): @@ -965,7 +965,7 @@ def AddTestarrayoftables(builder, testarrayoftables): def MonsterStartTestarrayoftablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartTestarrayoftablesVector(builder, numElems: int) -> int: +def StartTestarrayoftablesVector(builder, numElems): return MonsterStartTestarrayoftablesVector(builder, numElems) def MonsterAddEnemy(builder, enemy): @@ -983,7 +983,7 @@ def AddTestnestedflatbuffer(builder, testnestedflatbuffer): def MonsterStartTestnestedflatbufferVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def StartTestnestedflatbufferVector(builder, numElems: int) -> int: +def StartTestnestedflatbufferVector(builder, numElems): return MonsterStartTestnestedflatbufferVector(builder, numElems) def MonsterMakeTestnestedflatbufferVectorFromBytes(builder, bytes): @@ -1062,7 +1062,7 @@ def AddTestarrayofbools(builder, testarrayofbools): def MonsterStartTestarrayofboolsVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def StartTestarrayofboolsVector(builder, numElems: int) -> int: +def StartTestarrayofboolsVector(builder, numElems): return MonsterStartTestarrayofboolsVector(builder, numElems) def MonsterAddTestf(builder, testf): @@ -1092,7 +1092,7 @@ def AddTestarrayofstring2(builder, testarrayofstring2): def MonsterStartTestarrayofstring2Vector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartTestarrayofstring2Vector(builder, numElems: int) -> int: +def StartTestarrayofstring2Vector(builder, numElems): return MonsterStartTestarrayofstring2Vector(builder, numElems) def MonsterAddTestarrayofsortedstruct(builder, testarrayofsortedstruct): @@ -1104,7 +1104,7 @@ def AddTestarrayofsortedstruct(builder, testarrayofsortedstruct): def MonsterStartTestarrayofsortedstructVector(builder, numElems): return builder.StartVector(8, numElems, 4) -def StartTestarrayofsortedstructVector(builder, numElems: int) -> int: +def StartTestarrayofsortedstructVector(builder, numElems): return MonsterStartTestarrayofsortedstructVector(builder, numElems) def MonsterAddFlex(builder, flex): @@ -1116,7 +1116,7 @@ def AddFlex(builder, flex): def MonsterStartFlexVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def StartFlexVector(builder, numElems: int) -> int: +def StartFlexVector(builder, numElems): return MonsterStartFlexVector(builder, numElems) def MonsterAddTest5(builder, test5): @@ -1128,7 +1128,7 @@ def AddTest5(builder, test5): def MonsterStartTest5Vector(builder, numElems): return builder.StartVector(4, numElems, 2) -def StartTest5Vector(builder, numElems: int) -> int: +def StartTest5Vector(builder, numElems): return MonsterStartTest5Vector(builder, numElems) def MonsterAddVectorOfLongs(builder, vectorOfLongs): @@ -1140,7 +1140,7 @@ def AddVectorOfLongs(builder, vectorOfLongs): def MonsterStartVectorOfLongsVector(builder, numElems): return builder.StartVector(8, numElems, 8) -def StartVectorOfLongsVector(builder, numElems: int) -> int: +def StartVectorOfLongsVector(builder, numElems): return MonsterStartVectorOfLongsVector(builder, numElems) def MonsterAddVectorOfDoubles(builder, vectorOfDoubles): @@ -1152,7 +1152,7 @@ def AddVectorOfDoubles(builder, vectorOfDoubles): def MonsterStartVectorOfDoublesVector(builder, numElems): return builder.StartVector(8, numElems, 8) -def StartVectorOfDoublesVector(builder, numElems: int) -> int: +def StartVectorOfDoublesVector(builder, numElems): return MonsterStartVectorOfDoublesVector(builder, numElems) def MonsterAddParentNamespaceTest(builder, parentNamespaceTest): @@ -1170,7 +1170,7 @@ def AddVectorOfReferrables(builder, vectorOfReferrables): def MonsterStartVectorOfReferrablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartVectorOfReferrablesVector(builder, numElems: int) -> int: +def StartVectorOfReferrablesVector(builder, numElems): return MonsterStartVectorOfReferrablesVector(builder, numElems) def MonsterAddSingleWeakReference(builder, singleWeakReference): @@ -1188,7 +1188,7 @@ def AddVectorOfWeakReferences(builder, vectorOfWeakReferences): def MonsterStartVectorOfWeakReferencesVector(builder, numElems): return builder.StartVector(8, numElems, 8) -def StartVectorOfWeakReferencesVector(builder, numElems: int) -> int: +def StartVectorOfWeakReferencesVector(builder, numElems): return MonsterStartVectorOfWeakReferencesVector(builder, numElems) def MonsterAddVectorOfStrongReferrables(builder, vectorOfStrongReferrables): @@ -1200,7 +1200,7 @@ def AddVectorOfStrongReferrables(builder, vectorOfStrongReferrables): def MonsterStartVectorOfStrongReferrablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartVectorOfStrongReferrablesVector(builder, numElems: int) -> int: +def StartVectorOfStrongReferrablesVector(builder, numElems): return MonsterStartVectorOfStrongReferrablesVector(builder, numElems) def MonsterAddCoOwningReference(builder, coOwningReference): @@ -1218,7 +1218,7 @@ def AddVectorOfCoOwningReferences(builder, vectorOfCoOwningReferences): def MonsterStartVectorOfCoOwningReferencesVector(builder, numElems): return builder.StartVector(8, numElems, 8) -def StartVectorOfCoOwningReferencesVector(builder, numElems: int) -> int: +def StartVectorOfCoOwningReferencesVector(builder, numElems): return MonsterStartVectorOfCoOwningReferencesVector(builder, numElems) def MonsterAddNonOwningReference(builder, nonOwningReference): @@ -1236,7 +1236,7 @@ def AddVectorOfNonOwningReferences(builder, vectorOfNonOwningReferences): def MonsterStartVectorOfNonOwningReferencesVector(builder, numElems): return builder.StartVector(8, numElems, 8) -def StartVectorOfNonOwningReferencesVector(builder, numElems: int) -> int: +def StartVectorOfNonOwningReferencesVector(builder, numElems): return MonsterStartVectorOfNonOwningReferencesVector(builder, numElems) def MonsterAddAnyUniqueType(builder, anyUniqueType): @@ -1272,7 +1272,7 @@ def AddVectorOfEnums(builder, vectorOfEnums): def MonsterStartVectorOfEnumsVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def StartVectorOfEnumsVector(builder, numElems: int) -> int: +def StartVectorOfEnumsVector(builder, numElems): return MonsterStartVectorOfEnumsVector(builder, numElems) def MonsterAddSignedEnum(builder, signedEnum): @@ -1290,7 +1290,7 @@ def AddTestrequirednestedflatbuffer(builder, testrequirednestedflatbuffer): def MonsterStartTestrequirednestedflatbufferVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def StartTestrequirednestedflatbufferVector(builder, numElems: int) -> int: +def StartTestrequirednestedflatbufferVector(builder, numElems): return MonsterStartTestrequirednestedflatbufferVector(builder, numElems) def MonsterMakeTestrequirednestedflatbufferVectorFromBytes(builder, bytes): @@ -1309,7 +1309,7 @@ def AddScalarKeySortedTables(builder, scalarKeySortedTables): def MonsterStartScalarKeySortedTablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def StartScalarKeySortedTablesVector(builder, numElems: int) -> int: +def StartScalarKeySortedTablesVector(builder, numElems): return MonsterStartScalarKeySortedTablesVector(builder, numElems) def MonsterAddNativeInline(builder, nativeInline): diff --git a/tests/MyGame/Example/TypeAliases.py b/tests/MyGame/Example/TypeAliases.py index 00f90ed5b9c..b9cf4552ec9 100644 --- a/tests/MyGame/Example/TypeAliases.py +++ b/tests/MyGame/Example/TypeAliases.py @@ -227,7 +227,7 @@ def AddV8(builder, v8): def TypeAliasesStartV8Vector(builder, numElems): return builder.StartVector(1, numElems, 1) -def StartV8Vector(builder, numElems: int) -> int: +def StartV8Vector(builder, numElems): return TypeAliasesStartV8Vector(builder, numElems) def TypeAliasesAddVf64(builder, vf64): @@ -239,7 +239,7 @@ def AddVf64(builder, vf64): def TypeAliasesStartVf64Vector(builder, numElems): return builder.StartVector(8, numElems, 8) -def StartVf64Vector(builder, numElems: int) -> int: +def StartVf64Vector(builder, numElems): return TypeAliasesStartVf64Vector(builder, numElems) def TypeAliasesEnd(builder):