Skip to content

Commit

Permalink
Fix python type annotation output when not enabled
Browse files Browse the repository at this point in the history
Fixes #7971
  • Loading branch information
akb825 committed Nov 21, 2023
1 parent 5a937f1 commit 3ebb79a
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 44 deletions.
6 changes: 3 additions & 3 deletions python/flatbuffers/reflection/Enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions python/flatbuffers/reflection/EnumVal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions python/flatbuffers/reflection/Field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions python/flatbuffers/reflection/Object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions python/flatbuffers/reflection/RPCCall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions python/flatbuffers/reflection/Schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion python/flatbuffers/reflection/SchemaFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions python/flatbuffers/reflection/Service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down
8 changes: 6 additions & 2 deletions src/idl_gen_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,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";
}
Expand Down
40 changes: 20 additions & 20 deletions tests/MyGame/Example/Monster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tests/MyGame/Example/TypeAliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit 3ebb79a

Please sign in to comment.