diff --git a/src/idl_gen_python.cpp b/src/idl_gen_python.cpp index 1c814cd53cf..249c3d6916b 100644 --- a/src/idl_gen_python.cpp +++ b/src/idl_gen_python.cpp @@ -178,7 +178,7 @@ class PythonStubGenerator { case BASE_TYPE_STRUCT: { Import import = imports->Import(ModuleFor(val->union_type.struct_def), type(*val->union_type.struct_def)); - result += import.name; + result += "'" + import.name + "'"; break; } case BASE_TYPE_STRING: @@ -287,6 +287,62 @@ class PythonStubGenerator { } } + void GenerateObjectInitializerStub(std::stringstream &stub, + const StructDef *struct_def, + Imports *imports) const { + stub << " def __init__(self"; + + for (const FieldDef *field : struct_def->fields.vec) { + if (field->deprecated) continue; + + std::string field_name = namer_.Field(*field); + std::string field_type; + const Type &type = field->value.type; + + if (IsScalar(type.base_type)) { + field_type = TypeOf(type, imports); + if (field->IsOptional()) { field_type += " | None"; } + } else { + switch (type.base_type) { + case BASE_TYPE_STRUCT: { + Import import_ = + imports->Import(ModuleFor(type.struct_def), + namer_.ObjectType(*type.struct_def)); + field_type = "'" + import_.name + "' | None"; + break; + } + case BASE_TYPE_STRING: + field_type = "str | None"; + break; + case BASE_TYPE_ARRAY: + case BASE_TYPE_VECTOR: { + imports->Import("typing"); + if (type.element == BASE_TYPE_STRUCT) { + Import import_ = + imports->Import(ModuleFor(type.struct_def), + namer_.ObjectType(*type.struct_def)); + field_type = "typing.List['" + import_.name + "'] | None"; + } else if (type.element == BASE_TYPE_STRING) { + field_type = "typing.List[str] | None"; + } else { + field_type = "typing.List[" + TypeOf(type.VectorType(), imports) + + "] | None"; + } + break; + } + case BASE_TYPE_UNION: + field_type = UnionObjectType(*type.enum_def, imports); + break; + default: + field_type = "typing.Any"; + break; + } + } + stub << ", " << field_name << ": " << field_type << " = ..."; + } + stub << ") -> None: ...\n"; + } + void GenerateObjectStub(std::stringstream &stub, const StructDef *struct_def, Imports *imports) const { std::string name = namer_.ObjectType(*struct_def); @@ -299,6 +355,8 @@ class PythonStubGenerator { stub << " " << GenerateObjectFieldStub(field, imports) << "\n"; } + GenerateObjectInitializerStub(stub, struct_def, imports); + stub << " @classmethod\n"; stub << " def InitFromBuf(cls, buf: bytes, pos: int) -> " << name << ": ...\n"; @@ -1674,6 +1732,7 @@ class PythonGenerator : public BaseGenerator { field_type = package_reference + "." + field_type; import_list->insert("import " + package_reference); } + field_type = "'" + field_type + "'"; break; case BASE_TYPE_STRING: field_type += "str"; break; case BASE_TYPE_NONE: field_type += "None"; break; @@ -1694,20 +1753,17 @@ class PythonGenerator : public BaseGenerator { } void GenStructInit(const FieldDef &field, std::string *out_ptr, - std::set *import_list, - std::set *import_typing_list) const { - import_typing_list->insert("Optional"); + std::set *import_list) const { auto &output = *out_ptr; const Type &type = field.value.type; const std::string object_type = namer_.ObjectType(*type.struct_def); if (parser_.opts.include_dependence_headers) { auto package_reference = GenPackageReference(type); - output = package_reference + "." + object_type + "]"; + output = "'" + package_reference + "." + object_type + "'"; import_list->insert("import " + package_reference); } else { - output = object_type + "]"; + output = "'" + object_type + "'"; } - output = "Optional[" + output; } void GenVectorInit(const FieldDef &field, std::string *field_type_ptr, @@ -1720,13 +1776,15 @@ class PythonGenerator : public BaseGenerator { if (base_type == BASE_TYPE_STRUCT) { const std::string object_type = namer_.ObjectType(*vector_type.struct_def); - field_type = object_type + "]"; + std::string full_object_type; if (parser_.opts.include_dependence_headers) { auto package_reference = GenPackageReference(vector_type); - field_type = package_reference + "." + object_type + "]"; + full_object_type = package_reference + "." + object_type; import_list->insert("import " + package_reference); + } else { + full_object_type = object_type; } - field_type = "List[" + field_type; + field_type = "List['" + full_object_type + "']"; } else { field_type = "List[" + GetBasePythonTypeForScalarAndString(base_type) + "]"; @@ -1735,8 +1793,10 @@ class PythonGenerator : public BaseGenerator { void GenInitialize(const StructDef &struct_def, std::string *code_ptr, std::set *import_list) const { - std::string code; + std::string signature_params; + std::string init_body; std::set import_typing_list; + for (auto it = struct_def.fields.vec.begin(); it != struct_def.fields.vec.end(); ++it) { auto &field = **it; @@ -1751,7 +1811,7 @@ class PythonGenerator : public BaseGenerator { break; } case BASE_TYPE_STRUCT: { - GenStructInit(field, &field_type, import_list, &import_typing_list); + GenStructInit(field, &field_type, import_list); break; } case BASE_TYPE_VECTOR: @@ -1763,26 +1823,41 @@ class PythonGenerator : public BaseGenerator { // Scalar or sting fields. field_type = GetBasePythonTypeForScalarAndString(base_type); if (field.IsScalarOptional()) { + import_typing_list.insert("Optional"); field_type = "Optional[" + field_type + "]"; } break; } const auto default_value = GetDefaultValue(field); - // Wrties the init statement. const auto field_field = namer_.Field(field); - code += GenIndents(2) + "self." + field_field + " = " + default_value + - " # type: " + field_type; + + // If the default value is None, the type must be Optional, unless it's a + // Union that already contains None. + const bool is_already_optional = + (field_type.rfind("Optional[", 0) == 0) || + (field_type.rfind("Union[", 0) == 0); + if (default_value == "None" && !is_already_optional) { + import_typing_list.insert("Optional"); + field_type = "Optional[" + field_type + "]"; + } + + // Build signature with keyword arguments, type hints, and default values. + signature_params += + ", " + field_field + ": " + field_type + " = " + default_value; + + // Build the body of the __init__ method. + init_body += GenIndents(2) + "self." + field_field + " = " + field_field; } // Writes __init__ method. auto &code_base = *code_ptr; GenReceiverForObjectAPI(struct_def, code_ptr); - code_base += "__init__(self):"; - if (code.empty()) { + code_base += "__init__(self" + signature_params + "):"; + if (init_body.empty()) { code_base += GenIndents(2) + "pass"; } else { - code_base += code; + code_base += init_body; } code_base += "\n"; diff --git a/tests/MyGame/Example/Ability.py b/tests/MyGame/Example/Ability.py index e0344e5fd0e..236d580face 100644 --- a/tests/MyGame/Example/Ability.py +++ b/tests/MyGame/Example/Ability.py @@ -32,9 +32,9 @@ def CreateAbility(builder, id, distance): class AbilityT(object): # AbilityT - def __init__(self): - self.id = 0 # type: int - self.distance = 0 # type: int + def __init__(self, id: int = 0, distance: int = 0): + self.id = id + self.distance = distance @classmethod def InitFromBuf(cls, buf, pos): diff --git a/tests/MyGame/Example/ArrayStruct.py b/tests/MyGame/Example/ArrayStruct.py index a839c09f9c1..2364db5824a 100644 --- a/tests/MyGame/Example/ArrayStruct.py +++ b/tests/MyGame/Example/ArrayStruct.py @@ -107,20 +107,20 @@ def CreateArrayStruct(builder, a, b, c, d_a, d_b, d_c, d_d, e, f): import MyGame.Example.NestedStruct try: - from typing import List + from typing import List, Optional except: pass class ArrayStructT(object): # ArrayStructT - def __init__(self): - self.a = 0.0 # type: float - self.b = None # type: List[int] - self.c = 0 # type: int - self.d = None # type: List[MyGame.Example.NestedStruct.NestedStructT] - self.e = 0 # type: int - self.f = None # type: List[int] + def __init__(self, a: float = 0.0, b: Optional[List[int]] = None, c: int = 0, d: Optional[List['MyGame.Example.NestedStruct.NestedStructT']] = None, e: int = 0, f: Optional[List[int]] = None): + self.a = a + self.b = b + self.c = c + self.d = d + self.e = e + self.f = f @classmethod def InitFromBuf(cls, buf, pos): diff --git a/tests/MyGame/Example/ArrayStruct.pyi b/tests/MyGame/Example/ArrayStruct.pyi index 29bb83c6762..2b5f85d67cd 100644 --- a/tests/MyGame/Example/ArrayStruct.pyi +++ b/tests/MyGame/Example/ArrayStruct.pyi @@ -37,6 +37,7 @@ class ArrayStructT(object): d: typing.List[NestedStructT] e: int f: typing.List[int] + def __init__(self, a: float = ..., b: typing.List[int] | None = ..., c: int = ..., d: typing.List['NestedStructT'] | None = ..., e: int = ..., f: typing.List[int] | None = ...) -> None: ... @classmethod def InitFromBuf(cls, buf: bytes, pos: int) -> ArrayStructT: ... @classmethod diff --git a/tests/MyGame/Example/ArrayTable.py b/tests/MyGame/Example/ArrayTable.py index 7d314dfd517..0d825a73753 100644 --- a/tests/MyGame/Example/ArrayTable.py +++ b/tests/MyGame/Example/ArrayTable.py @@ -68,8 +68,8 @@ def End(builder: flatbuffers.Builder) -> int: class ArrayTableT(object): # ArrayTableT - def __init__(self): - self.a = None # type: Optional[MyGame.Example.ArrayStruct.ArrayStructT] + def __init__(self, a: Optional['MyGame.Example.ArrayStruct.ArrayStructT'] = None): + self.a = a @classmethod def InitFromBuf(cls, buf, pos): diff --git a/tests/MyGame/Example/ArrayTable.pyi b/tests/MyGame/Example/ArrayTable.pyi index 10f2af31951..d243de579ae 100644 --- a/tests/MyGame/Example/ArrayTable.pyi +++ b/tests/MyGame/Example/ArrayTable.pyi @@ -21,6 +21,7 @@ class ArrayTable(object): def A(self) -> ArrayStruct | None: ... class ArrayTableT(object): a: ArrayStructT | None + def __init__(self, a: 'ArrayStructT' | None = ...) -> None: ... @classmethod def InitFromBuf(cls, buf: bytes, pos: int) -> ArrayTableT: ... @classmethod diff --git a/tests/MyGame/Example/Monster.py b/tests/MyGame/Example/Monster.py index 9fb81446efc..7890ccca6ba 100644 --- a/tests/MyGame/Example/Monster.py +++ b/tests/MyGame/Example/Monster.py @@ -1403,68 +1403,68 @@ def End(builder): class MonsterT(object): # MonsterT - def __init__(self): - self.pos = None # type: Optional[MyGame.Example.Vec3.Vec3T] - self.mana = 150 # type: int - self.hp = 100 # type: int - self.name = None # type: str - self.inventory = None # type: List[int] - self.color = 8 # type: int - self.testType = 0 # type: int - self.test = None # type: Union[None, MyGame.Example.Monster.MonsterT, MyGame.Example.TestSimpleTableWithEnum.TestSimpleTableWithEnumT, MyGame.Example2.Monster.MonsterT] - self.test4 = None # type: List[MyGame.Example.Test.TestT] - self.testarrayofstring = None # type: List[str] - self.testarrayoftables = None # type: List[MyGame.Example.Monster.MonsterT] - self.enemy = None # type: Optional[MyGame.Example.Monster.MonsterT] - self.testnestedflatbuffer = None # type: List[int] - self.testempty = None # type: Optional[MyGame.Example.Stat.StatT] - self.testbool = False # type: bool - self.testhashs32Fnv1 = 0 # type: int - self.testhashu32Fnv1 = 0 # type: int - self.testhashs64Fnv1 = 0 # type: int - self.testhashu64Fnv1 = 0 # type: int - self.testhashs32Fnv1a = 0 # type: int - self.testhashu32Fnv1a = 0 # type: int - self.testhashs64Fnv1a = 0 # type: int - self.testhashu64Fnv1a = 0 # type: int - self.testarrayofbools = None # type: List[bool] - self.testf = 3.14159 # type: float - self.testf2 = 3.0 # type: float - self.testf3 = 0.0 # type: float - self.testarrayofstring2 = None # type: List[str] - self.testarrayofsortedstruct = None # type: List[MyGame.Example.Ability.AbilityT] - self.flex = None # type: List[int] - self.test5 = None # type: List[MyGame.Example.Test.TestT] - self.vectorOfLongs = None # type: List[int] - self.vectorOfDoubles = None # type: List[float] - self.parentNamespaceTest = None # type: Optional[MyGame.InParentNamespace.InParentNamespaceT] - self.vectorOfReferrables = None # type: List[MyGame.Example.Referrable.ReferrableT] - self.singleWeakReference = 0 # type: int - self.vectorOfWeakReferences = None # type: List[int] - self.vectorOfStrongReferrables = None # type: List[MyGame.Example.Referrable.ReferrableT] - self.coOwningReference = 0 # type: int - self.vectorOfCoOwningReferences = None # type: List[int] - self.nonOwningReference = 0 # type: int - self.vectorOfNonOwningReferences = None # type: List[int] - self.anyUniqueType = 0 # type: int - self.anyUnique = None # type: Union[None, MyGame.Example.Monster.MonsterT, MyGame.Example.TestSimpleTableWithEnum.TestSimpleTableWithEnumT, MyGame.Example2.Monster.MonsterT] - self.anyAmbiguousType = 0 # type: int - self.anyAmbiguous = None # type: Union[None, MyGame.Example.Monster.MonsterT, MyGame.Example.Monster.MonsterT, MyGame.Example.Monster.MonsterT] - self.vectorOfEnums = None # type: List[int] - self.signedEnum = -1 # type: int - self.testrequirednestedflatbuffer = None # type: List[int] - self.scalarKeySortedTables = None # type: List[MyGame.Example.Stat.StatT] - self.nativeInline = None # type: Optional[MyGame.Example.Test.TestT] - self.longEnumNonEnumDefault = 0 # type: int - self.longEnumNormalDefault = 2 # type: int - self.nanDefault = float('nan') # type: float - self.infDefault = float('inf') # type: float - self.positiveInfDefault = float('inf') # type: float - self.infinityDefault = float('inf') # type: float - self.positiveInfinityDefault = float('inf') # type: float - self.negativeInfDefault = float('-inf') # type: float - self.negativeInfinityDefault = float('-inf') # type: float - self.doubleInfDefault = float('inf') # type: float + def __init__(self, pos: Optional['MyGame.Example.Vec3.Vec3T'] = None, mana: int = 150, hp: int = 100, name: Optional[str] = None, inventory: Optional[List[int]] = None, color: int = 8, testType: int = 0, test: Union[None, 'MyGame.Example.Monster.MonsterT', 'MyGame.Example.TestSimpleTableWithEnum.TestSimpleTableWithEnumT', 'MyGame.Example2.Monster.MonsterT'] = None, test4: Optional[List['MyGame.Example.Test.TestT']] = None, testarrayofstring: Optional[List[str]] = None, testarrayoftables: Optional[List['MyGame.Example.Monster.MonsterT']] = None, enemy: Optional['MyGame.Example.Monster.MonsterT'] = None, testnestedflatbuffer: Optional[List[int]] = None, testempty: Optional['MyGame.Example.Stat.StatT'] = None, testbool: bool = False, testhashs32Fnv1: int = 0, testhashu32Fnv1: int = 0, testhashs64Fnv1: int = 0, testhashu64Fnv1: int = 0, testhashs32Fnv1a: int = 0, testhashu32Fnv1a: int = 0, testhashs64Fnv1a: int = 0, testhashu64Fnv1a: int = 0, testarrayofbools: Optional[List[bool]] = None, testf: float = 3.14159, testf2: float = 3.0, testf3: float = 0.0, testarrayofstring2: Optional[List[str]] = None, testarrayofsortedstruct: Optional[List['MyGame.Example.Ability.AbilityT']] = None, flex: Optional[List[int]] = None, test5: Optional[List['MyGame.Example.Test.TestT']] = None, vectorOfLongs: Optional[List[int]] = None, vectorOfDoubles: Optional[List[float]] = None, parentNamespaceTest: Optional['MyGame.InParentNamespace.InParentNamespaceT'] = None, vectorOfReferrables: Optional[List['MyGame.Example.Referrable.ReferrableT']] = None, singleWeakReference: int = 0, vectorOfWeakReferences: Optional[List[int]] = None, vectorOfStrongReferrables: Optional[List['MyGame.Example.Referrable.ReferrableT']] = None, coOwningReference: int = 0, vectorOfCoOwningReferences: Optional[List[int]] = None, nonOwningReference: int = 0, vectorOfNonOwningReferences: Optional[List[int]] = None, anyUniqueType: int = 0, anyUnique: Union[None, 'MyGame.Example.Monster.MonsterT', 'MyGame.Example.TestSimpleTableWithEnum.TestSimpleTableWithEnumT', 'MyGame.Example2.Monster.MonsterT'] = None, anyAmbiguousType: int = 0, anyAmbiguous: Union[None, 'MyGame.Example.Monster.MonsterT', 'MyGame.Example.Monster.MonsterT', 'MyGame.Example.Monster.MonsterT'] = None, vectorOfEnums: Optional[List[int]] = None, signedEnum: int = -1, testrequirednestedflatbuffer: Optional[List[int]] = None, scalarKeySortedTables: Optional[List['MyGame.Example.Stat.StatT']] = None, nativeInline: Optional['MyGame.Example.Test.TestT'] = None, longEnumNonEnumDefault: int = 0, longEnumNormalDefault: int = 2, nanDefault: float = float('nan'), infDefault: float = float('inf'), positiveInfDefault: float = float('inf'), infinityDefault: float = float('inf'), positiveInfinityDefault: float = float('inf'), negativeInfDefault: float = float('-inf'), negativeInfinityDefault: float = float('-inf'), doubleInfDefault: float = float('inf')): + self.pos = pos + self.mana = mana + self.hp = hp + self.name = name + self.inventory = inventory + self.color = color + self.testType = testType + self.test = test + self.test4 = test4 + self.testarrayofstring = testarrayofstring + self.testarrayoftables = testarrayoftables + self.enemy = enemy + self.testnestedflatbuffer = testnestedflatbuffer + self.testempty = testempty + self.testbool = testbool + self.testhashs32Fnv1 = testhashs32Fnv1 + self.testhashu32Fnv1 = testhashu32Fnv1 + self.testhashs64Fnv1 = testhashs64Fnv1 + self.testhashu64Fnv1 = testhashu64Fnv1 + self.testhashs32Fnv1a = testhashs32Fnv1a + self.testhashu32Fnv1a = testhashu32Fnv1a + self.testhashs64Fnv1a = testhashs64Fnv1a + self.testhashu64Fnv1a = testhashu64Fnv1a + self.testarrayofbools = testarrayofbools + self.testf = testf + self.testf2 = testf2 + self.testf3 = testf3 + self.testarrayofstring2 = testarrayofstring2 + self.testarrayofsortedstruct = testarrayofsortedstruct + self.flex = flex + self.test5 = test5 + self.vectorOfLongs = vectorOfLongs + self.vectorOfDoubles = vectorOfDoubles + self.parentNamespaceTest = parentNamespaceTest + self.vectorOfReferrables = vectorOfReferrables + self.singleWeakReference = singleWeakReference + self.vectorOfWeakReferences = vectorOfWeakReferences + self.vectorOfStrongReferrables = vectorOfStrongReferrables + self.coOwningReference = coOwningReference + self.vectorOfCoOwningReferences = vectorOfCoOwningReferences + self.nonOwningReference = nonOwningReference + self.vectorOfNonOwningReferences = vectorOfNonOwningReferences + self.anyUniqueType = anyUniqueType + self.anyUnique = anyUnique + self.anyAmbiguousType = anyAmbiguousType + self.anyAmbiguous = anyAmbiguous + self.vectorOfEnums = vectorOfEnums + self.signedEnum = signedEnum + self.testrequirednestedflatbuffer = testrequirednestedflatbuffer + self.scalarKeySortedTables = scalarKeySortedTables + self.nativeInline = nativeInline + self.longEnumNonEnumDefault = longEnumNonEnumDefault + self.longEnumNormalDefault = longEnumNormalDefault + self.nanDefault = nanDefault + self.infDefault = infDefault + self.positiveInfDefault = positiveInfDefault + self.infinityDefault = infinityDefault + self.positiveInfinityDefault = positiveInfinityDefault + self.negativeInfDefault = negativeInfDefault + self.negativeInfinityDefault = negativeInfinityDefault + self.doubleInfDefault = doubleInfDefault @classmethod def InitFromBuf(cls, buf, pos): diff --git a/tests/MyGame/Example/NestedStruct.py b/tests/MyGame/Example/NestedStruct.py index d5d672a2eab..a443d4de3ae 100644 --- a/tests/MyGame/Example/NestedStruct.py +++ b/tests/MyGame/Example/NestedStruct.py @@ -97,18 +97,18 @@ def CreateNestedStruct(builder, a, b, c, d): return builder.Offset() try: - from typing import List + from typing import List, Optional except: pass class NestedStructT(object): # NestedStructT - def __init__(self): - self.a = None # type: List[int] - self.b = 0 # type: int - self.c = None # type: List[int] - self.d = None # type: List[int] + def __init__(self, a: Optional[List[int]] = None, b: int = 0, c: Optional[List[int]] = None, d: Optional[List[int]] = None): + self.a = a + self.b = b + self.c = c + self.d = d @classmethod def InitFromBuf(cls, buf, pos): diff --git a/tests/MyGame/Example/NestedStruct.pyi b/tests/MyGame/Example/NestedStruct.pyi index 09e6fc68927..78569af8c98 100644 --- a/tests/MyGame/Example/NestedStruct.pyi +++ b/tests/MyGame/Example/NestedStruct.pyi @@ -33,6 +33,7 @@ class NestedStructT(object): b: typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C] c: typing.List[typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C]] d: typing.List[int] + def __init__(self, a: typing.List[int] | None = ..., b: typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C] = ..., c: typing.List[typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C]] | None = ..., d: typing.List[int] | None = ...) -> None: ... @classmethod def InitFromBuf(cls, buf: bytes, pos: int) -> NestedStructT: ... @classmethod diff --git a/tests/MyGame/Example/NestedUnion/Any.pyi b/tests/MyGame/Example/NestedUnion/Any.pyi index dee0f7f2e38..04fd6ba6357 100644 --- a/tests/MyGame/Example/NestedUnion/Any.pyi +++ b/tests/MyGame/Example/NestedUnion/Any.pyi @@ -16,5 +16,5 @@ class Any(object): NONE: int Vec3: int TestSimpleTableWithEnum: int -def AnyCreator(union_type: typing.Literal[Any.NONE, Any.Vec3, Any.TestSimpleTableWithEnum], table: table.Table) -> typing.Union[None, Vec3, TestSimpleTableWithEnum]: ... +def AnyCreator(union_type: typing.Literal[Any.NONE, Any.Vec3, Any.TestSimpleTableWithEnum], table: table.Table) -> typing.Union[None, 'Vec3', 'TestSimpleTableWithEnum']: ... diff --git a/tests/MyGame/Example/NestedUnion/NestedUnionTest.py b/tests/MyGame/Example/NestedUnion/NestedUnionTest.py index 7540b6e8ad6..3cddfe56c81 100644 --- a/tests/MyGame/Example/NestedUnion/NestedUnionTest.py +++ b/tests/MyGame/Example/NestedUnion/NestedUnionTest.py @@ -97,18 +97,18 @@ def End(builder: flatbuffers.Builder) -> int: import MyGame.Example.NestedUnion.TestSimpleTableWithEnum import MyGame.Example.NestedUnion.Vec3 try: - from typing import Union + from typing import Optional, Union except: pass class NestedUnionTestT(object): # NestedUnionTestT - def __init__(self): - self.name = None # type: str - self.dataType = 0 # type: int - self.data = None # type: Union[None, MyGame.Example.NestedUnion.Vec3.Vec3T, MyGame.Example.NestedUnion.TestSimpleTableWithEnum.TestSimpleTableWithEnumT] - self.id = 0 # type: int + def __init__(self, name: Optional[str] = None, dataType: int = 0, data: Union[None, 'MyGame.Example.NestedUnion.Vec3.Vec3T', 'MyGame.Example.NestedUnion.TestSimpleTableWithEnum.TestSimpleTableWithEnumT'] = None, id: int = 0): + self.name = name + self.dataType = dataType + self.data = data + self.id = id @classmethod def InitFromBuf(cls, buf, pos): diff --git a/tests/MyGame/Example/NestedUnion/NestedUnionTest.pyi b/tests/MyGame/Example/NestedUnion/NestedUnionTest.pyi index 06a906d4024..44ae9c53363 100644 --- a/tests/MyGame/Example/NestedUnion/NestedUnionTest.pyi +++ b/tests/MyGame/Example/NestedUnion/NestedUnionTest.pyi @@ -26,8 +26,9 @@ class NestedUnionTest(object): class NestedUnionTestT(object): name: str | None dataType: typing.Literal[Any.NONE, Any.Vec3, Any.TestSimpleTableWithEnum] - data: typing.Union[None, Vec3T, TestSimpleTableWithEnumT] + data: typing.Union[None, 'Vec3T', 'TestSimpleTableWithEnumT'] id: int + def __init__(self, name: str | None = ..., dataType: typing.Literal[Any.NONE, Any.Vec3, Any.TestSimpleTableWithEnum] = ..., data: typing.Union[None, 'Vec3T', 'TestSimpleTableWithEnumT'] = ..., id: int = ...) -> None: ... @classmethod def InitFromBuf(cls, buf: bytes, pos: int) -> NestedUnionTestT: ... @classmethod diff --git a/tests/MyGame/Example/NestedUnion/Test.py b/tests/MyGame/Example/NestedUnion/Test.py index e4e90be27f4..30afebf67d7 100644 --- a/tests/MyGame/Example/NestedUnion/Test.py +++ b/tests/MyGame/Example/NestedUnion/Test.py @@ -34,9 +34,9 @@ def CreateTest(builder, a, b): class TestT(object): # TestT - def __init__(self): - self.a = 0 # type: int - self.b = 0 # type: int + def __init__(self, a: int = 0, b: int = 0): + self.a = a + self.b = b @classmethod def InitFromBuf(cls, buf, pos): diff --git a/tests/MyGame/Example/NestedUnion/Test.pyi b/tests/MyGame/Example/NestedUnion/Test.pyi index 2fa64aa8202..a87a0ed27ae 100644 --- a/tests/MyGame/Example/NestedUnion/Test.pyi +++ b/tests/MyGame/Example/NestedUnion/Test.pyi @@ -19,6 +19,7 @@ class Test(object): class TestT(object): a: int b: int + def __init__(self, a: int = ..., b: int = ...) -> None: ... @classmethod def InitFromBuf(cls, buf: bytes, pos: int) -> TestT: ... @classmethod diff --git a/tests/MyGame/Example/NestedUnion/TestSimpleTableWithEnum.py b/tests/MyGame/Example/NestedUnion/TestSimpleTableWithEnum.py index 9b7ef28c01f..e0855179f54 100644 --- a/tests/MyGame/Example/NestedUnion/TestSimpleTableWithEnum.py +++ b/tests/MyGame/Example/NestedUnion/TestSimpleTableWithEnum.py @@ -54,8 +54,8 @@ def End(builder: flatbuffers.Builder) -> int: class TestSimpleTableWithEnumT(object): # TestSimpleTableWithEnumT - def __init__(self): - self.color = 2 # type: int + def __init__(self, color: int = 2): + self.color = color @classmethod def InitFromBuf(cls, buf, pos): diff --git a/tests/MyGame/Example/NestedUnion/TestSimpleTableWithEnum.pyi b/tests/MyGame/Example/NestedUnion/TestSimpleTableWithEnum.pyi index 117b19d532d..61e8ecd0834 100644 --- a/tests/MyGame/Example/NestedUnion/TestSimpleTableWithEnum.pyi +++ b/tests/MyGame/Example/NestedUnion/TestSimpleTableWithEnum.pyi @@ -19,6 +19,7 @@ class TestSimpleTableWithEnum(object): def Color(self) -> typing.Literal[Color.Red, Color.Green, Color.Blue]: ... class TestSimpleTableWithEnumT(object): color: typing.Literal[Color.Red, Color.Green, Color.Blue] + def __init__(self, color: typing.Literal[Color.Red, Color.Green, Color.Blue] = ...) -> None: ... @classmethod def InitFromBuf(cls, buf: bytes, pos: int) -> TestSimpleTableWithEnumT: ... @classmethod diff --git a/tests/MyGame/Example/NestedUnion/Vec3.py b/tests/MyGame/Example/NestedUnion/Vec3.py index d0f8676f46e..b84210f09e9 100644 --- a/tests/MyGame/Example/NestedUnion/Vec3.py +++ b/tests/MyGame/Example/NestedUnion/Vec3.py @@ -129,13 +129,13 @@ def End(builder: flatbuffers.Builder) -> int: class Vec3T(object): # Vec3T - def __init__(self): - self.x = 0.0 # type: float - self.y = 0.0 # type: float - self.z = 0.0 # type: float - self.test1 = 0.0 # type: float - self.test2 = 0 # type: int - self.test3 = None # type: Optional[MyGame.Example.NestedUnion.Test.TestT] + def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0, test1: float = 0.0, test2: int = 0, test3: Optional['MyGame.Example.NestedUnion.Test.TestT'] = None): + self.x = x + self.y = y + self.z = z + self.test1 = test1 + self.test2 = test2 + self.test3 = test3 @classmethod def InitFromBuf(cls, buf, pos): diff --git a/tests/MyGame/Example/NestedUnion/Vec3.pyi b/tests/MyGame/Example/NestedUnion/Vec3.pyi index c570c20b4c1..71a45f96165 100644 --- a/tests/MyGame/Example/NestedUnion/Vec3.pyi +++ b/tests/MyGame/Example/NestedUnion/Vec3.pyi @@ -30,6 +30,7 @@ class Vec3T(object): test1: float test2: typing.Literal[Color.Red, Color.Green, Color.Blue] test3: TestT | None + def __init__(self, x: float = ..., y: float = ..., z: float = ..., test1: float = ..., test2: typing.Literal[Color.Red, Color.Green, Color.Blue] = ..., test3: 'TestT' | None = ...) -> None: ... @classmethod def InitFromBuf(cls, buf: bytes, pos: int) -> Vec3T: ... @classmethod diff --git a/tests/MyGame/Example/Referrable.py b/tests/MyGame/Example/Referrable.py index 9cc5f5724d3..4c998dbb833 100644 --- a/tests/MyGame/Example/Referrable.py +++ b/tests/MyGame/Example/Referrable.py @@ -57,8 +57,8 @@ def End(builder): class ReferrableT(object): # ReferrableT - def __init__(self): - self.id = 0 # type: int + def __init__(self, id: int = 0): + self.id = id @classmethod def InitFromBuf(cls, buf, pos): diff --git a/tests/MyGame/Example/Stat.py b/tests/MyGame/Example/Stat.py index ec6b9d9a227..f330bf60a33 100644 --- a/tests/MyGame/Example/Stat.py +++ b/tests/MyGame/Example/Stat.py @@ -79,14 +79,18 @@ def StatEnd(builder): def End(builder): return StatEnd(builder) +try: + from typing import Optional +except: + pass class StatT(object): # StatT - def __init__(self): - self.id = None # type: str - self.val = 0 # type: int - self.count = 0 # type: int + def __init__(self, id: Optional[str] = None, val: int = 0, count: int = 0): + self.id = id + self.val = val + self.count = count @classmethod def InitFromBuf(cls, buf, pos): diff --git a/tests/MyGame/Example/StructOfStructs.py b/tests/MyGame/Example/StructOfStructs.py index 88c469ed7c4..a18c12ed027 100644 --- a/tests/MyGame/Example/StructOfStructs.py +++ b/tests/MyGame/Example/StructOfStructs.py @@ -57,10 +57,10 @@ def CreateStructOfStructs(builder, a_id, a_distance, b_a, b_b, c_id, c_distance) class StructOfStructsT(object): # StructOfStructsT - def __init__(self): - self.a = None # type: Optional[MyGame.Example.Ability.AbilityT] - self.b = None # type: Optional[MyGame.Example.Test.TestT] - self.c = None # type: Optional[MyGame.Example.Ability.AbilityT] + def __init__(self, a: Optional['MyGame.Example.Ability.AbilityT'] = None, b: Optional['MyGame.Example.Test.TestT'] = None, c: Optional['MyGame.Example.Ability.AbilityT'] = None): + self.a = a + self.b = b + self.c = c @classmethod def InitFromBuf(cls, buf, pos): diff --git a/tests/MyGame/Example/StructOfStructsOfStructs.py b/tests/MyGame/Example/StructOfStructsOfStructs.py index 0243f71c4d4..845d403eee9 100644 --- a/tests/MyGame/Example/StructOfStructsOfStructs.py +++ b/tests/MyGame/Example/StructOfStructsOfStructs.py @@ -47,8 +47,8 @@ def CreateStructOfStructsOfStructs(builder, a_a_id, a_a_distance, a_b_a, a_b_b, class StructOfStructsOfStructsT(object): # StructOfStructsOfStructsT - def __init__(self): - self.a = None # type: Optional[MyGame.Example.StructOfStructs.StructOfStructsT] + def __init__(self, a: Optional['MyGame.Example.StructOfStructs.StructOfStructsT'] = None): + self.a = a @classmethod def InitFromBuf(cls, buf, pos): diff --git a/tests/MyGame/Example/Test.py b/tests/MyGame/Example/Test.py index f095d33451a..82e1144d3db 100644 --- a/tests/MyGame/Example/Test.py +++ b/tests/MyGame/Example/Test.py @@ -33,9 +33,9 @@ def CreateTest(builder, a, b): class TestT(object): # TestT - def __init__(self): - self.a = 0 # type: int - self.b = 0 # type: int + def __init__(self, a: int = 0, b: int = 0): + self.a = a + self.b = b @classmethod def InitFromBuf(cls, buf, pos): diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.py b/tests/MyGame/Example/TestSimpleTableWithEnum.py index 520d257fd7f..878274ad2fc 100644 --- a/tests/MyGame/Example/TestSimpleTableWithEnum.py +++ b/tests/MyGame/Example/TestSimpleTableWithEnum.py @@ -57,8 +57,8 @@ def End(builder): class TestSimpleTableWithEnumT(object): # TestSimpleTableWithEnumT - def __init__(self): - self.color = 2 # type: int + def __init__(self, color: int = 2): + self.color = color @classmethod def InitFromBuf(cls, buf, pos): diff --git a/tests/MyGame/Example/TypeAliases.py b/tests/MyGame/Example/TypeAliases.py index b9cf4552ec9..21a276057aa 100644 --- a/tests/MyGame/Example/TypeAliases.py +++ b/tests/MyGame/Example/TypeAliases.py @@ -249,26 +249,26 @@ def End(builder): return TypeAliasesEnd(builder) try: - from typing import List + from typing import List, Optional except: pass class TypeAliasesT(object): # TypeAliasesT - def __init__(self): - self.i8 = 0 # type: int - self.u8 = 0 # type: int - self.i16 = 0 # type: int - self.u16 = 0 # type: int - self.i32 = 0 # type: int - self.u32 = 0 # type: int - self.i64 = 0 # type: int - self.u64 = 0 # type: int - self.f32 = 0.0 # type: float - self.f64 = 0.0 # type: float - self.v8 = None # type: List[int] - self.vf64 = None # type: List[float] + def __init__(self, i8: int = 0, u8: int = 0, i16: int = 0, u16: int = 0, i32: int = 0, u32: int = 0, i64: int = 0, u64: int = 0, f32: float = 0.0, f64: float = 0.0, v8: Optional[List[int]] = None, vf64: Optional[List[float]] = None): + self.i8 = i8 + self.u8 = u8 + self.i16 = i16 + self.u16 = u16 + self.i32 = i32 + self.u32 = u32 + self.i64 = i64 + self.u64 = u64 + self.f32 = f32 + self.f64 = f64 + self.v8 = v8 + self.vf64 = vf64 @classmethod def InitFromBuf(cls, buf, pos): diff --git a/tests/MyGame/Example/Vec3.py b/tests/MyGame/Example/Vec3.py index 3a394a269ce..e04b3ce607c 100644 --- a/tests/MyGame/Example/Vec3.py +++ b/tests/MyGame/Example/Vec3.py @@ -58,13 +58,13 @@ def CreateVec3(builder, x, y, z, test1, test2, test3_a, test3_b): class Vec3T(object): # Vec3T - def __init__(self): - self.x = 0.0 # type: float - self.y = 0.0 # type: float - self.z = 0.0 # type: float - self.test1 = 0.0 # type: float - self.test2 = 0 # type: int - self.test3 = None # type: Optional[MyGame.Example.Test.TestT] + def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0, test1: float = 0.0, test2: int = 0, test3: Optional['MyGame.Example.Test.TestT'] = None): + self.x = x + self.y = y + self.z = z + self.test1 = test1 + self.test2 = test2 + self.test3 = test3 @classmethod def InitFromBuf(cls, buf, pos): diff --git a/tests/MyGame/MonsterExtra.py b/tests/MyGame/MonsterExtra.py index d9e183617c3..c08846fd1aa 100644 --- a/tests/MyGame/MonsterExtra.py +++ b/tests/MyGame/MonsterExtra.py @@ -224,24 +224,24 @@ def End(builder: flatbuffers.Builder) -> int: return MonsterExtraEnd(builder) try: - from typing import List + from typing import List, Optional except: pass class MonsterExtraT(object): # MonsterExtraT - def __init__(self): - self.d0 = float('nan') # type: float - self.d1 = float('nan') # type: float - self.d2 = float('inf') # type: float - self.d3 = float('-inf') # type: float - self.f0 = float('nan') # type: float - self.f1 = float('nan') # type: float - self.f2 = float('inf') # type: float - self.f3 = float('-inf') # type: float - self.dvec = None # type: List[float] - self.fvec = None # type: List[float] + def __init__(self, d0: float = float('nan'), d1: float = float('nan'), d2: float = float('inf'), d3: float = float('-inf'), f0: float = float('nan'), f1: float = float('nan'), f2: float = float('inf'), f3: float = float('-inf'), dvec: Optional[List[float]] = None, fvec: Optional[List[float]] = None): + self.d0 = d0 + self.d1 = d1 + self.d2 = d2 + self.d3 = d3 + self.f0 = f0 + self.f1 = f1 + self.f2 = f2 + self.f3 = f3 + self.dvec = dvec + self.fvec = fvec @classmethod def InitFromBuf(cls, buf, pos): diff --git a/tests/MyGame/MonsterExtra.pyi b/tests/MyGame/MonsterExtra.pyi index 693cc512673..39c2226cd4a 100644 --- a/tests/MyGame/MonsterExtra.pyi +++ b/tests/MyGame/MonsterExtra.pyi @@ -44,6 +44,7 @@ class MonsterExtraT(object): f3: float dvec: typing.List[float] fvec: typing.List[float] + def __init__(self, d0: float = ..., d1: float = ..., d2: float = ..., d3: float = ..., f0: float = ..., f1: float = ..., f2: float = ..., f3: float = ..., dvec: typing.List[float] | None = ..., fvec: typing.List[float] | None = ...) -> None: ... @classmethod def InitFromBuf(cls, buf: bytes, pos: int) -> MonsterExtraT: ... @classmethod diff --git a/tests/monster_test_generated.py b/tests/monster_test_generated.py index 71139c65c06..f759dcfb653 100644 --- a/tests/monster_test_generated.py +++ b/tests/monster_test_generated.py @@ -243,9 +243,9 @@ def CreateTest(builder, a, b): class TestT(object): # TestT - def __init__(self): - self.a = 0 # type: int - self.b = 0 # type: int + def __init__(self, a: int = 0, b: int = 0): + self.a = a + self.b = b @classmethod def InitFromBuf(cls, buf, pos): @@ -319,8 +319,8 @@ def TestSimpleTableWithEnumEnd(builder): class TestSimpleTableWithEnumT(object): # TestSimpleTableWithEnumT - def __init__(self): - self.color = 2 # type: int + def __init__(self, color: int = 2): + self.color = color @classmethod def InitFromBuf(cls, buf, pos): @@ -404,13 +404,13 @@ def CreateVec3(builder, x, y, z, test1, test2, test3_a, test3_b): class Vec3T(object): # Vec3T - def __init__(self): - self.x = 0.0 # type: float - self.y = 0.0 # type: float - self.z = 0.0 # type: float - self.test1 = 0.0 # type: float - self.test2 = 0 # type: int - self.test3 = None # type: Optional[TestT] + def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0, test1: float = 0.0, test2: int = 0, test3: Optional['TestT'] = None): + self.x = x + self.y = y + self.z = z + self.test1 = test1 + self.test2 = test2 + self.test3 = test3 @classmethod def InitFromBuf(cls, buf, pos): @@ -472,9 +472,9 @@ def CreateAbility(builder, id, distance): class AbilityT(object): # AbilityT - def __init__(self): - self.id = 0 # type: int - self.distance = 0 # type: int + def __init__(self, id: int = 0, distance: int = 0): + self.id = id + self.distance = distance @classmethod def InitFromBuf(cls, buf, pos): @@ -554,10 +554,10 @@ def CreateStructOfStructs(builder, a_id, a_distance, b_a, b_b, c_id, c_distance) class StructOfStructsT(object): # StructOfStructsT - def __init__(self): - self.a = None # type: Optional[AbilityT] - self.b = None # type: Optional[TestT] - self.c = None # type: Optional[AbilityT] + def __init__(self, a: Optional['AbilityT'] = None, b: Optional['TestT'] = None, c: Optional['AbilityT'] = None): + self.a = a + self.b = b + self.c = c @classmethod def InitFromBuf(cls, buf, pos): @@ -632,8 +632,8 @@ def CreateStructOfStructsOfStructs(builder, a_a_id, a_a_distance, a_b_a, a_b_b, class StructOfStructsOfStructsT(object): # StructOfStructsOfStructsT - def __init__(self): - self.a = None # type: Optional[StructOfStructsT] + def __init__(self, a: Optional['StructOfStructsT'] = None): + self.a = a @classmethod def InitFromBuf(cls, buf, pos): @@ -723,14 +723,18 @@ def StatEnd(builder): return builder.EndObject() +try: + from typing import Optional +except: + pass class StatT(object): # StatT - def __init__(self): - self.id = None # type: str - self.val = 0 # type: int - self.count = 0 # type: int + def __init__(self, id: Optional[str] = None, val: int = 0, count: int = 0): + self.id = id + self.val = val + self.count = count @classmethod def InitFromBuf(cls, buf, pos): @@ -813,8 +817,8 @@ def ReferrableEnd(builder): class ReferrableT(object): # ReferrableT - def __init__(self): - self.id = 0 # type: int + def __init__(self, id: int = 0): + self.id = id @classmethod def InitFromBuf(cls, buf, pos): @@ -1969,68 +1973,68 @@ def MonsterEnd(builder): class MonsterT(object): # MonsterT - def __init__(self): - self.pos = None # type: Optional[Vec3T] - self.mana = 150 # type: int - self.hp = 100 # type: int - self.name = None # type: str - self.inventory = None # type: List[int] - self.color = 8 # type: int - self.testType = 0 # type: int - self.test = None # type: Union[None, MonsterT, TestSimpleTableWithEnumT, MonsterT] - self.test4 = None # type: List[TestT] - self.testarrayofstring = None # type: List[str] - self.testarrayoftables = None # type: List[MonsterT] - self.enemy = None # type: Optional[MonsterT] - self.testnestedflatbuffer = None # type: List[int] - self.testempty = None # type: Optional[StatT] - self.testbool = False # type: bool - self.testhashs32Fnv1 = 0 # type: int - self.testhashu32Fnv1 = 0 # type: int - self.testhashs64Fnv1 = 0 # type: int - self.testhashu64Fnv1 = 0 # type: int - self.testhashs32Fnv1a = 0 # type: int - self.testhashu32Fnv1a = 0 # type: int - self.testhashs64Fnv1a = 0 # type: int - self.testhashu64Fnv1a = 0 # type: int - self.testarrayofbools = None # type: List[bool] - self.testf = 3.14159 # type: float - self.testf2 = 3.0 # type: float - self.testf3 = 0.0 # type: float - self.testarrayofstring2 = None # type: List[str] - self.testarrayofsortedstruct = None # type: List[AbilityT] - self.flex = None # type: List[int] - self.test5 = None # type: List[TestT] - self.vectorOfLongs = None # type: List[int] - self.vectorOfDoubles = None # type: List[float] - self.parentNamespaceTest = None # type: Optional[InParentNamespaceT] - self.vectorOfReferrables = None # type: List[ReferrableT] - self.singleWeakReference = 0 # type: int - self.vectorOfWeakReferences = None # type: List[int] - self.vectorOfStrongReferrables = None # type: List[ReferrableT] - self.coOwningReference = 0 # type: int - self.vectorOfCoOwningReferences = None # type: List[int] - self.nonOwningReference = 0 # type: int - self.vectorOfNonOwningReferences = None # type: List[int] - self.anyUniqueType = 0 # type: int - self.anyUnique = None # type: Union[None, MonsterT, TestSimpleTableWithEnumT, MonsterT] - self.anyAmbiguousType = 0 # type: int - self.anyAmbiguous = None # type: Union[None, MonsterT, MonsterT, MonsterT] - self.vectorOfEnums = None # type: List[int] - self.signedEnum = -1 # type: int - self.testrequirednestedflatbuffer = None # type: List[int] - self.scalarKeySortedTables = None # type: List[StatT] - self.nativeInline = None # type: Optional[TestT] - self.longEnumNonEnumDefault = 0 # type: int - self.longEnumNormalDefault = 2 # type: int - self.nanDefault = float('nan') # type: float - self.infDefault = float('inf') # type: float - self.positiveInfDefault = float('inf') # type: float - self.infinityDefault = float('inf') # type: float - self.positiveInfinityDefault = float('inf') # type: float - self.negativeInfDefault = float('-inf') # type: float - self.negativeInfinityDefault = float('-inf') # type: float - self.doubleInfDefault = float('inf') # type: float + def __init__(self, pos: Optional['Vec3T'] = None, mana: int = 150, hp: int = 100, name: Optional[str] = None, inventory: Optional[List[int]] = None, color: int = 8, testType: int = 0, test: Union[None, 'MonsterT', 'TestSimpleTableWithEnumT', 'MonsterT'] = None, test4: Optional[List['TestT']] = None, testarrayofstring: Optional[List[str]] = None, testarrayoftables: Optional[List['MonsterT']] = None, enemy: Optional['MonsterT'] = None, testnestedflatbuffer: Optional[List[int]] = None, testempty: Optional['StatT'] = None, testbool: bool = False, testhashs32Fnv1: int = 0, testhashu32Fnv1: int = 0, testhashs64Fnv1: int = 0, testhashu64Fnv1: int = 0, testhashs32Fnv1a: int = 0, testhashu32Fnv1a: int = 0, testhashs64Fnv1a: int = 0, testhashu64Fnv1a: int = 0, testarrayofbools: Optional[List[bool]] = None, testf: float = 3.14159, testf2: float = 3.0, testf3: float = 0.0, testarrayofstring2: Optional[List[str]] = None, testarrayofsortedstruct: Optional[List['AbilityT']] = None, flex: Optional[List[int]] = None, test5: Optional[List['TestT']] = None, vectorOfLongs: Optional[List[int]] = None, vectorOfDoubles: Optional[List[float]] = None, parentNamespaceTest: Optional['InParentNamespaceT'] = None, vectorOfReferrables: Optional[List['ReferrableT']] = None, singleWeakReference: int = 0, vectorOfWeakReferences: Optional[List[int]] = None, vectorOfStrongReferrables: Optional[List['ReferrableT']] = None, coOwningReference: int = 0, vectorOfCoOwningReferences: Optional[List[int]] = None, nonOwningReference: int = 0, vectorOfNonOwningReferences: Optional[List[int]] = None, anyUniqueType: int = 0, anyUnique: Union[None, 'MonsterT', 'TestSimpleTableWithEnumT', 'MonsterT'] = None, anyAmbiguousType: int = 0, anyAmbiguous: Union[None, 'MonsterT', 'MonsterT', 'MonsterT'] = None, vectorOfEnums: Optional[List[int]] = None, signedEnum: int = -1, testrequirednestedflatbuffer: Optional[List[int]] = None, scalarKeySortedTables: Optional[List['StatT']] = None, nativeInline: Optional['TestT'] = None, longEnumNonEnumDefault: int = 0, longEnumNormalDefault: int = 2, nanDefault: float = float('nan'), infDefault: float = float('inf'), positiveInfDefault: float = float('inf'), infinityDefault: float = float('inf'), positiveInfinityDefault: float = float('inf'), negativeInfDefault: float = float('-inf'), negativeInfinityDefault: float = float('-inf'), doubleInfDefault: float = float('inf')): + self.pos = pos + self.mana = mana + self.hp = hp + self.name = name + self.inventory = inventory + self.color = color + self.testType = testType + self.test = test + self.test4 = test4 + self.testarrayofstring = testarrayofstring + self.testarrayoftables = testarrayoftables + self.enemy = enemy + self.testnestedflatbuffer = testnestedflatbuffer + self.testempty = testempty + self.testbool = testbool + self.testhashs32Fnv1 = testhashs32Fnv1 + self.testhashu32Fnv1 = testhashu32Fnv1 + self.testhashs64Fnv1 = testhashs64Fnv1 + self.testhashu64Fnv1 = testhashu64Fnv1 + self.testhashs32Fnv1a = testhashs32Fnv1a + self.testhashu32Fnv1a = testhashu32Fnv1a + self.testhashs64Fnv1a = testhashs64Fnv1a + self.testhashu64Fnv1a = testhashu64Fnv1a + self.testarrayofbools = testarrayofbools + self.testf = testf + self.testf2 = testf2 + self.testf3 = testf3 + self.testarrayofstring2 = testarrayofstring2 + self.testarrayofsortedstruct = testarrayofsortedstruct + self.flex = flex + self.test5 = test5 + self.vectorOfLongs = vectorOfLongs + self.vectorOfDoubles = vectorOfDoubles + self.parentNamespaceTest = parentNamespaceTest + self.vectorOfReferrables = vectorOfReferrables + self.singleWeakReference = singleWeakReference + self.vectorOfWeakReferences = vectorOfWeakReferences + self.vectorOfStrongReferrables = vectorOfStrongReferrables + self.coOwningReference = coOwningReference + self.vectorOfCoOwningReferences = vectorOfCoOwningReferences + self.nonOwningReference = nonOwningReference + self.vectorOfNonOwningReferences = vectorOfNonOwningReferences + self.anyUniqueType = anyUniqueType + self.anyUnique = anyUnique + self.anyAmbiguousType = anyAmbiguousType + self.anyAmbiguous = anyAmbiguous + self.vectorOfEnums = vectorOfEnums + self.signedEnum = signedEnum + self.testrequirednestedflatbuffer = testrequirednestedflatbuffer + self.scalarKeySortedTables = scalarKeySortedTables + self.nativeInline = nativeInline + self.longEnumNonEnumDefault = longEnumNonEnumDefault + self.longEnumNormalDefault = longEnumNormalDefault + self.nanDefault = nanDefault + self.infDefault = infDefault + self.positiveInfDefault = positiveInfDefault + self.infinityDefault = infinityDefault + self.positiveInfinityDefault = positiveInfinityDefault + self.negativeInfDefault = negativeInfDefault + self.negativeInfinityDefault = negativeInfinityDefault + self.doubleInfDefault = doubleInfDefault @classmethod def InitFromBuf(cls, buf, pos): @@ -2701,26 +2705,26 @@ def TypeAliasesEnd(builder): try: - from typing import List + from typing import List, Optional except: pass class TypeAliasesT(object): # TypeAliasesT - def __init__(self): - self.i8 = 0 # type: int - self.u8 = 0 # type: int - self.i16 = 0 # type: int - self.u16 = 0 # type: int - self.i32 = 0 # type: int - self.u32 = 0 # type: int - self.i64 = 0 # type: int - self.u64 = 0 # type: int - self.f32 = 0.0 # type: float - self.f64 = 0.0 # type: float - self.v8 = None # type: List[int] - self.vf64 = None # type: List[float] + def __init__(self, i8: int = 0, u8: int = 0, i16: int = 0, u16: int = 0, i32: int = 0, u32: int = 0, i64: int = 0, u64: int = 0, f32: float = 0.0, f64: float = 0.0, v8: Optional[List[int]] = None, vf64: Optional[List[float]] = None): + self.i8 = i8 + self.u8 = u8 + self.i16 = i16 + self.u16 = u16 + self.i32 = i32 + self.u32 = u32 + self.i64 = i64 + self.u64 = u64 + self.f32 = f32 + self.f64 = f64 + self.v8 = v8 + self.vf64 = vf64 @classmethod def InitFromBuf(cls, buf, pos):