[Python] Enhance object API __init__ with typed keyword arguments (#8615)

This commit significantly improves the developer experience for the Python Object-Based API by overhauling the generated `__init__` method for `T`-suffixed classes.

Previously, `T` objects had to be instantiated with an empty constructor, and their fields had to be populated manually one by one. This was verbose and not idiomatic Python.

This change modifies the Python code generator (`GenInitialize`) to produce `__init__` methods that are:

1.  **Keyword-Argument-Friendly**: The constructor now accepts all table/struct fields as keyword arguments, allowing for concise, single-line object creation.

2.  **Fully Typed**: The signature of the `__init__` method is now annotated with Python type hints. This provides immediate benefits for static analysis tools (like Mypy) and IDEs, enabling better autocompletion and type checking.

3.  **Correctly Optional**: The generator now correctly wraps types in `Optional[...]` if their default value is `None`. This applies to strings, vectors, and other nullable fields, ensuring strict type safety.

The new approach remains **fully backward-compatible**, as all arguments have default values. Existing code that uses the empty constructor will continue to work without modification.

#### Example of a Generated `__init__`

**Before:**

```python
class KeyValueT(object):
    def __init__(self):
        self.key = None  # type: str
        self.value = None  # type: str
```

**After:**

```python
class KeyValueT(object):
    def __init__(self, key: Optional[str] = None, value: Optional[str] = None):
        self.key = key
        self.value = value
```

#### Example of User Code

**Before:**

```python
# Old, verbose way
kv = KeyValueT()
kv.key = "instrument"
kv.value = "EUR/USD"
```

**After:**

```python
# New, Pythonic way
kv = KeyValueT(key="instrument", value="EUR/USD")
```
This commit is contained in:
Łukasz Kurowski
2025-07-23 08:57:39 +02:00
committed by GitHub
parent ca73ff34b7
commit c526cb640b
31 changed files with 745 additions and 293 deletions

View File

@@ -287,6 +287,63 @@ class PythonStubGenerator {
} }
} }
void GenerateObjectInitializerStub(std::stringstream &stub,
const StructDef *struct_def,
Imports *imports) const {
stub << " def __init__(\n";
stub << " self,\n";
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 << " = ...,\n";
}
stub << " ) -> None: ...\n";
}
void GenerateObjectStub(std::stringstream &stub, const StructDef *struct_def, void GenerateObjectStub(std::stringstream &stub, const StructDef *struct_def,
Imports *imports) const { Imports *imports) const {
std::string name = namer_.ObjectType(*struct_def); std::string name = namer_.ObjectType(*struct_def);
@@ -300,6 +357,8 @@ class PythonStubGenerator {
stub << " " << GenerateObjectFieldStub(field, imports) << "\n"; stub << " " << GenerateObjectFieldStub(field, imports) << "\n";
} }
GenerateObjectInitializerStub(stub, struct_def, imports);
stub << " @classmethod\n"; stub << " @classmethod\n";
stub << " def InitFromBuf(cls, buf: bytes, pos: int) -> " << name stub << " def InitFromBuf(cls, buf: bytes, pos: int) -> " << name
<< ": ...\n"; << ": ...\n";
@@ -1694,6 +1753,7 @@ class PythonGenerator : public BaseGenerator {
field_type = package_reference + "." + field_type; field_type = package_reference + "." + field_type;
import_list->insert("import " + package_reference); import_list->insert("import " + package_reference);
} }
field_type = "'" + field_type + "'";
break; break;
case BASE_TYPE_STRING: field_type += "str"; break; case BASE_TYPE_STRING: field_type += "str"; break;
case BASE_TYPE_NONE: field_type += "None"; break; case BASE_TYPE_NONE: field_type += "None"; break;
@@ -1755,8 +1815,12 @@ class PythonGenerator : public BaseGenerator {
void GenInitialize(const StructDef &struct_def, std::string *code_ptr, void GenInitialize(const StructDef &struct_def, std::string *code_ptr,
std::set<std::string> *import_list) const { std::set<std::string> *import_list) const {
std::string code; std::string signature_params;
std::string init_body;
std::set<std::string> import_typing_list; std::set<std::string> import_typing_list;
signature_params += GenIndents(2) + "self,";
for (auto it = struct_def.fields.vec.begin(); for (auto it = struct_def.fields.vec.begin();
it != struct_def.fields.vec.end(); ++it) { it != struct_def.fields.vec.end(); ++it) {
auto &field = **it; auto &field = **it;
@@ -1783,6 +1847,7 @@ class PythonGenerator : public BaseGenerator {
// Scalar or sting fields. // Scalar or sting fields.
field_type = GetBasePythonTypeForScalarAndString(base_type); field_type = GetBasePythonTypeForScalarAndString(base_type);
if (field.IsScalarOptional()) { if (field.IsScalarOptional()) {
import_typing_list.insert("Optional");
field_type = "Optional[" + field_type + "]"; field_type = "Optional[" + field_type + "]";
} }
break; break;
@@ -1791,18 +1856,23 @@ class PythonGenerator : public BaseGenerator {
const auto default_value = GetDefaultValue(field); const auto default_value = GetDefaultValue(field);
// Writes the init statement. // Writes the init statement.
const auto field_field = namer_.Field(field); const auto field_field = namer_.Field(field);
code += GenIndents(2) + "self." + field_field + " = " + default_value +
" # type: " + field_type; // Build signature with keyword arguments, type hints, and default values.
signature_params += GenIndents(2) + field_field + " = " + default_value + ",";
// Build the body of the __init__ method.
init_body += GenIndents(2) + "self." + field_field + " = " + field_field +
" # type: " + field_type;
} }
// Writes __init__ method. // Writes __init__ method.
auto &code_base = *code_ptr; auto &code_base = *code_ptr;
GenReceiverForObjectAPI(struct_def, code_ptr); GenReceiverForObjectAPI(struct_def, code_ptr);
code_base += "__init__(self):"; code_base += "__init__(" + signature_params + GenIndents(1) + "):";
if (code.empty()) { if (init_body.empty()) {
code_base += GenIndents(2) + "pass"; code_base += GenIndents(2) + "pass";
} else { } else {
code_base += code; code_base += init_body;
} }
code_base += "\n"; code_base += "\n";

View File

@@ -32,9 +32,13 @@ def CreateAbility(builder, id, distance):
class AbilityT(object): class AbilityT(object):
# AbilityT # AbilityT
def __init__(self): def __init__(
self.id = 0 # type: int self,
self.distance = 0 # type: int id = 0,
distance = 0,
):
self.id = id # type: int
self.distance = distance # type: int
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -114,13 +114,21 @@ except:
class ArrayStructT(object): class ArrayStructT(object):
# ArrayStructT # ArrayStructT
def __init__(self): def __init__(
self.a = 0.0 # type: float self,
self.b = None # type: Optional[List[int]] a = 0.0,
self.c = 0 # type: int b = None,
self.d = None # type: Optional[List[MyGame.Example.NestedStruct.NestedStructT]] c = 0,
self.e = 0 # type: int d = None,
self.f = None # type: Optional[List[int]] e = 0,
f = None,
):
self.a = a # type: float
self.b = b # type: Optional[List[int]]
self.c = c # type: int
self.d = d # type: Optional[List[MyGame.Example.NestedStruct.NestedStructT]]
self.e = e # type: int
self.f = f # type: Optional[List[int]]
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -35,6 +35,15 @@ class ArrayStructT(object):
d: typing.List[NestedStructT] d: typing.List[NestedStructT]
e: int e: int
f: typing.List[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 @classmethod
def InitFromBuf(cls, buf: bytes, pos: int) -> ArrayStructT: ... def InitFromBuf(cls, buf: bytes, pos: int) -> ArrayStructT: ...
@classmethod @classmethod

View File

@@ -68,8 +68,11 @@ except:
class ArrayTableT(object): class ArrayTableT(object):
# ArrayTableT # ArrayTableT
def __init__(self): def __init__(
self.a = None # type: Optional[MyGame.Example.ArrayStruct.ArrayStructT] self,
a = None,
):
self.a = a # type: Optional[MyGame.Example.ArrayStruct.ArrayStructT]
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -19,6 +19,10 @@ class ArrayTable(object):
def A(self) -> ArrayStruct | None: ... def A(self) -> ArrayStruct | None: ...
class ArrayTableT(object): class ArrayTableT(object):
a: ArrayStructT | None a: ArrayStructT | None
def __init__(
self,
a: 'ArrayStructT' | None = ...,
) -> None: ...
@classmethod @classmethod
def InitFromBuf(cls, buf: bytes, pos: int) -> ArrayTableT: ... def InitFromBuf(cls, buf: bytes, pos: int) -> ArrayTableT: ...
@classmethod @classmethod

View File

@@ -1403,68 +1403,131 @@ except:
class MonsterT(object): class MonsterT(object):
# MonsterT # MonsterT
def __init__(self): def __init__(
self.pos = None # type: Optional[MyGame.Example.Vec3.Vec3T] self,
self.mana = 150 # type: int pos = None,
self.hp = 100 # type: int mana = 150,
self.name = None # type: Optional[str] hp = 100,
self.inventory = None # type: Optional[List[int]] name = None,
self.color = 8 # type: int inventory = None,
self.testType = 0 # type: int color = 8,
self.test = None # type: Union[None, MyGame.Example.Monster.MonsterT, MyGame.Example.TestSimpleTableWithEnum.TestSimpleTableWithEnumT, MyGame.Example2.Monster.MonsterT] testType = 0,
self.test4 = None # type: Optional[List[MyGame.Example.Test.TestT]] test = None,
self.testarrayofstring = None # type: Optional[List[Optional[str]]] test4 = None,
self.testarrayoftables = None # type: Optional[List[MyGame.Example.Monster.MonsterT]] testarrayofstring = None,
self.enemy = None # type: Optional[MyGame.Example.Monster.MonsterT] testarrayoftables = None,
self.testnestedflatbuffer = None # type: Optional[List[int]] enemy = None,
self.testempty = None # type: Optional[MyGame.Example.Stat.StatT] testnestedflatbuffer = None,
self.testbool = False # type: bool testempty = None,
self.testhashs32Fnv1 = 0 # type: int testbool = False,
self.testhashu32Fnv1 = 0 # type: int testhashs32Fnv1 = 0,
self.testhashs64Fnv1 = 0 # type: int testhashu32Fnv1 = 0,
self.testhashu64Fnv1 = 0 # type: int testhashs64Fnv1 = 0,
self.testhashs32Fnv1a = 0 # type: int testhashu64Fnv1 = 0,
self.testhashu32Fnv1a = 0 # type: int testhashs32Fnv1a = 0,
self.testhashs64Fnv1a = 0 # type: int testhashu32Fnv1a = 0,
self.testhashu64Fnv1a = 0 # type: int testhashs64Fnv1a = 0,
self.testarrayofbools = None # type: Optional[List[bool]] testhashu64Fnv1a = 0,
self.testf = 3.14159 # type: float testarrayofbools = None,
self.testf2 = 3.0 # type: float testf = 3.14159,
self.testf3 = 0.0 # type: float testf2 = 3.0,
self.testarrayofstring2 = None # type: Optional[List[Optional[str]]] testf3 = 0.0,
self.testarrayofsortedstruct = None # type: Optional[List[MyGame.Example.Ability.AbilityT]] testarrayofstring2 = None,
self.flex = None # type: Optional[List[int]] testarrayofsortedstruct = None,
self.test5 = None # type: Optional[List[MyGame.Example.Test.TestT]] flex = None,
self.vectorOfLongs = None # type: Optional[List[int]] test5 = None,
self.vectorOfDoubles = None # type: Optional[List[float]] vectorOfLongs = None,
self.parentNamespaceTest = None # type: Optional[MyGame.InParentNamespace.InParentNamespaceT] vectorOfDoubles = None,
self.vectorOfReferrables = None # type: Optional[List[MyGame.Example.Referrable.ReferrableT]] parentNamespaceTest = None,
self.singleWeakReference = 0 # type: int vectorOfReferrables = None,
self.vectorOfWeakReferences = None # type: Optional[List[int]] singleWeakReference = 0,
self.vectorOfStrongReferrables = None # type: Optional[List[MyGame.Example.Referrable.ReferrableT]] vectorOfWeakReferences = None,
self.coOwningReference = 0 # type: int vectorOfStrongReferrables = None,
self.vectorOfCoOwningReferences = None # type: Optional[List[int]] coOwningReference = 0,
self.nonOwningReference = 0 # type: int vectorOfCoOwningReferences = None,
self.vectorOfNonOwningReferences = None # type: Optional[List[int]] nonOwningReference = 0,
self.anyUniqueType = 0 # type: int vectorOfNonOwningReferences = None,
self.anyUnique = None # type: Union[None, MyGame.Example.Monster.MonsterT, MyGame.Example.TestSimpleTableWithEnum.TestSimpleTableWithEnumT, MyGame.Example2.Monster.MonsterT] anyUniqueType = 0,
self.anyAmbiguousType = 0 # type: int anyUnique = None,
self.anyAmbiguous = None # type: Union[None, MyGame.Example.Monster.MonsterT, MyGame.Example.Monster.MonsterT, MyGame.Example.Monster.MonsterT] anyAmbiguousType = 0,
self.vectorOfEnums = None # type: Optional[List[int]] anyAmbiguous = None,
self.signedEnum = -1 # type: int vectorOfEnums = None,
self.testrequirednestedflatbuffer = None # type: Optional[List[int]] signedEnum = -1,
self.scalarKeySortedTables = None # type: Optional[List[MyGame.Example.Stat.StatT]] testrequirednestedflatbuffer = None,
self.nativeInline = None # type: Optional[MyGame.Example.Test.TestT] scalarKeySortedTables = None,
self.longEnumNonEnumDefault = 0 # type: int nativeInline = None,
self.longEnumNormalDefault = 2 # type: int longEnumNonEnumDefault = 0,
self.nanDefault = float('nan') # type: float longEnumNormalDefault = 2,
self.infDefault = float('inf') # type: float nanDefault = float('nan'),
self.positiveInfDefault = float('inf') # type: float infDefault = float('inf'),
self.infinityDefault = float('inf') # type: float positiveInfDefault = float('inf'),
self.positiveInfinityDefault = float('inf') # type: float infinityDefault = float('inf'),
self.negativeInfDefault = float('-inf') # type: float positiveInfinityDefault = float('inf'),
self.negativeInfinityDefault = float('-inf') # type: float negativeInfDefault = float('-inf'),
self.doubleInfDefault = float('inf') # type: float negativeInfinityDefault = float('-inf'),
doubleInfDefault = float('inf'),
):
self.pos = pos # type: Optional[MyGame.Example.Vec3.Vec3T]
self.mana = mana # type: int
self.hp = hp # type: int
self.name = name # type: Optional[str]
self.inventory = inventory # type: Optional[List[int]]
self.color = color # type: int
self.testType = testType # type: int
self.test = test # type: Union[None, 'MyGame.Example.Monster.MonsterT', 'MyGame.Example.TestSimpleTableWithEnum.TestSimpleTableWithEnumT', 'MyGame.Example2.Monster.MonsterT']
self.test4 = test4 # type: Optional[List[MyGame.Example.Test.TestT]]
self.testarrayofstring = testarrayofstring # type: Optional[List[Optional[str]]]
self.testarrayoftables = testarrayoftables # type: Optional[List[MyGame.Example.Monster.MonsterT]]
self.enemy = enemy # type: Optional[MyGame.Example.Monster.MonsterT]
self.testnestedflatbuffer = testnestedflatbuffer # type: Optional[List[int]]
self.testempty = testempty # type: Optional[MyGame.Example.Stat.StatT]
self.testbool = testbool # type: bool
self.testhashs32Fnv1 = testhashs32Fnv1 # type: int
self.testhashu32Fnv1 = testhashu32Fnv1 # type: int
self.testhashs64Fnv1 = testhashs64Fnv1 # type: int
self.testhashu64Fnv1 = testhashu64Fnv1 # type: int
self.testhashs32Fnv1a = testhashs32Fnv1a # type: int
self.testhashu32Fnv1a = testhashu32Fnv1a # type: int
self.testhashs64Fnv1a = testhashs64Fnv1a # type: int
self.testhashu64Fnv1a = testhashu64Fnv1a # type: int
self.testarrayofbools = testarrayofbools # type: Optional[List[bool]]
self.testf = testf # type: float
self.testf2 = testf2 # type: float
self.testf3 = testf3 # type: float
self.testarrayofstring2 = testarrayofstring2 # type: Optional[List[Optional[str]]]
self.testarrayofsortedstruct = testarrayofsortedstruct # type: Optional[List[MyGame.Example.Ability.AbilityT]]
self.flex = flex # type: Optional[List[int]]
self.test5 = test5 # type: Optional[List[MyGame.Example.Test.TestT]]
self.vectorOfLongs = vectorOfLongs # type: Optional[List[int]]
self.vectorOfDoubles = vectorOfDoubles # type: Optional[List[float]]
self.parentNamespaceTest = parentNamespaceTest # type: Optional[MyGame.InParentNamespace.InParentNamespaceT]
self.vectorOfReferrables = vectorOfReferrables # type: Optional[List[MyGame.Example.Referrable.ReferrableT]]
self.singleWeakReference = singleWeakReference # type: int
self.vectorOfWeakReferences = vectorOfWeakReferences # type: Optional[List[int]]
self.vectorOfStrongReferrables = vectorOfStrongReferrables # type: Optional[List[MyGame.Example.Referrable.ReferrableT]]
self.coOwningReference = coOwningReference # type: int
self.vectorOfCoOwningReferences = vectorOfCoOwningReferences # type: Optional[List[int]]
self.nonOwningReference = nonOwningReference # type: int
self.vectorOfNonOwningReferences = vectorOfNonOwningReferences # type: Optional[List[int]]
self.anyUniqueType = anyUniqueType # type: int
self.anyUnique = anyUnique # type: Union[None, 'MyGame.Example.Monster.MonsterT', 'MyGame.Example.TestSimpleTableWithEnum.TestSimpleTableWithEnumT', 'MyGame.Example2.Monster.MonsterT']
self.anyAmbiguousType = anyAmbiguousType # type: int
self.anyAmbiguous = anyAmbiguous # type: Union[None, 'MyGame.Example.Monster.MonsterT', 'MyGame.Example.Monster.MonsterT', 'MyGame.Example.Monster.MonsterT']
self.vectorOfEnums = vectorOfEnums # type: Optional[List[int]]
self.signedEnum = signedEnum # type: int
self.testrequirednestedflatbuffer = testrequirednestedflatbuffer # type: Optional[List[int]]
self.scalarKeySortedTables = scalarKeySortedTables # type: Optional[List[MyGame.Example.Stat.StatT]]
self.nativeInline = nativeInline # type: Optional[MyGame.Example.Test.TestT]
self.longEnumNonEnumDefault = longEnumNonEnumDefault # type: int
self.longEnumNormalDefault = longEnumNormalDefault # type: int
self.nanDefault = nanDefault # type: float
self.infDefault = infDefault # type: float
self.positiveInfDefault = positiveInfDefault # type: float
self.infinityDefault = infinityDefault # type: float
self.positiveInfinityDefault = positiveInfinityDefault # type: float
self.negativeInfDefault = negativeInfDefault # type: float
self.negativeInfinityDefault = negativeInfinityDefault # type: float
self.doubleInfDefault = doubleInfDefault # type: float
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -104,11 +104,17 @@ except:
class NestedStructT(object): class NestedStructT(object):
# NestedStructT # NestedStructT
def __init__(self): def __init__(
self.a = None # type: Optional[List[int]] self,
self.b = 0 # type: int a = None,
self.c = None # type: Optional[List[int]] b = 0,
self.d = None # type: Optional[List[int]] c = None,
d = None,
):
self.a = a # type: Optional[List[int]]
self.b = b # type: int
self.c = c # type: Optional[List[int]]
self.d = d # type: Optional[List[int]]
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -31,6 +31,13 @@ class NestedStructT(object):
b: typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C] b: typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C]
c: typing.List[typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C]] c: typing.List[typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C]]
d: typing.List[int] 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 @classmethod
def InitFromBuf(cls, buf: bytes, pos: int) -> NestedStructT: ... def InitFromBuf(cls, buf: bytes, pos: int) -> NestedStructT: ...
@classmethod @classmethod

View File

@@ -104,11 +104,17 @@ except:
class NestedUnionTestT(object): class NestedUnionTestT(object):
# NestedUnionTestT # NestedUnionTestT
def __init__(self): def __init__(
self.name = None # type: Optional[str] self,
self.dataType = 0 # type: int name = None,
self.data = None # type: Union[None, MyGame.Example.NestedUnion.Vec3.Vec3T, MyGame.Example.NestedUnion.TestSimpleTableWithEnum.TestSimpleTableWithEnumT] dataType = 0,
self.id = 0 # type: int data = None,
id = 0,
):
self.name = name # type: Optional[str]
self.dataType = dataType # type: int
self.data = data # type: Union[None, 'MyGame.Example.NestedUnion.Vec3.Vec3T', 'MyGame.Example.NestedUnion.TestSimpleTableWithEnum.TestSimpleTableWithEnumT']
self.id = id # type: int
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -26,6 +26,13 @@ class NestedUnionTestT(object):
dataType: typing.Literal[Any.NONE, Any.Vec3, Any.TestSimpleTableWithEnum] dataType: typing.Literal[Any.NONE, Any.Vec3, Any.TestSimpleTableWithEnum]
data: typing.Union[None, Vec3T, TestSimpleTableWithEnumT] data: typing.Union[None, Vec3T, TestSimpleTableWithEnumT]
id: int 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 @classmethod
def InitFromBuf(cls, buf: bytes, pos: int) -> NestedUnionTestT: ... def InitFromBuf(cls, buf: bytes, pos: int) -> NestedUnionTestT: ...
@classmethod @classmethod

View File

@@ -34,9 +34,13 @@ def CreateTest(builder, a, b):
class TestT(object): class TestT(object):
# TestT # TestT
def __init__(self): def __init__(
self.a = 0 # type: int self,
self.b = 0 # type: int a = 0,
b = 0,
):
self.a = a # type: int
self.b = b # type: int
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -17,6 +17,11 @@ class Test(object):
class TestT(object): class TestT(object):
a: int a: int
b: int b: int
def __init__(
self,
a: int = ...,
b: int = ...,
) -> None: ...
@classmethod @classmethod
def InitFromBuf(cls, buf: bytes, pos: int) -> TestT: ... def InitFromBuf(cls, buf: bytes, pos: int) -> TestT: ...
@classmethod @classmethod

View File

@@ -54,8 +54,11 @@ def End(builder: flatbuffers.Builder) -> int:
class TestSimpleTableWithEnumT(object): class TestSimpleTableWithEnumT(object):
# TestSimpleTableWithEnumT # TestSimpleTableWithEnumT
def __init__(self): def __init__(
self.color = 2 # type: int self,
color = 2,
):
self.color = color # type: int
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -17,6 +17,10 @@ class TestSimpleTableWithEnum(object):
def Color(self) -> typing.Literal[Color.Red, Color.Green, Color.Blue]: ... def Color(self) -> typing.Literal[Color.Red, Color.Green, Color.Blue]: ...
class TestSimpleTableWithEnumT(object): class TestSimpleTableWithEnumT(object):
color: typing.Literal[Color.Red, Color.Green, Color.Blue] color: typing.Literal[Color.Red, Color.Green, Color.Blue]
def __init__(
self,
color: typing.Literal[Color.Red, Color.Green, Color.Blue] = ...,
) -> None: ...
@classmethod @classmethod
def InitFromBuf(cls, buf: bytes, pos: int) -> TestSimpleTableWithEnumT: ... def InitFromBuf(cls, buf: bytes, pos: int) -> TestSimpleTableWithEnumT: ...
@classmethod @classmethod

View File

@@ -129,13 +129,21 @@ except:
class Vec3T(object): class Vec3T(object):
# Vec3T # Vec3T
def __init__(self): def __init__(
self.x = 0.0 # type: float self,
self.y = 0.0 # type: float x = 0.0,
self.z = 0.0 # type: float y = 0.0,
self.test1 = 0.0 # type: float z = 0.0,
self.test2 = 0 # type: int test1 = 0.0,
self.test3 = None # type: Optional[MyGame.Example.NestedUnion.Test.TestT] test2 = 0,
test3 = None,
):
self.x = x # type: float
self.y = y # type: float
self.z = z # type: float
self.test1 = test1 # type: float
self.test2 = test2 # type: int
self.test3 = test3 # type: Optional[MyGame.Example.NestedUnion.Test.TestT]
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -28,6 +28,15 @@ class Vec3T(object):
test1: float test1: float
test2: typing.Literal[Color.Red, Color.Green, Color.Blue] test2: typing.Literal[Color.Red, Color.Green, Color.Blue]
test3: TestT | None 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 @classmethod
def InitFromBuf(cls, buf: bytes, pos: int) -> Vec3T: ... def InitFromBuf(cls, buf: bytes, pos: int) -> Vec3T: ...
@classmethod @classmethod

View File

@@ -57,8 +57,11 @@ def End(builder):
class ReferrableT(object): class ReferrableT(object):
# ReferrableT # ReferrableT
def __init__(self): def __init__(
self.id = 0 # type: int self,
id = 0,
):
self.id = id # type: int
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -83,10 +83,15 @@ def End(builder):
class StatT(object): class StatT(object):
# StatT # StatT
def __init__(self): def __init__(
self.id = None # type: Optional[str] self,
self.val = 0 # type: int id = None,
self.count = 0 # type: int val = 0,
count = 0,
):
self.id = id # type: Optional[str]
self.val = val # type: int
self.count = count # type: int
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -57,10 +57,15 @@ except:
class StructOfStructsT(object): class StructOfStructsT(object):
# StructOfStructsT # StructOfStructsT
def __init__(self): def __init__(
self.a = None # type: Optional[MyGame.Example.Ability.AbilityT] self,
self.b = None # type: Optional[MyGame.Example.Test.TestT] a = None,
self.c = None # type: Optional[MyGame.Example.Ability.AbilityT] b = None,
c = None,
):
self.a = a # type: Optional[MyGame.Example.Ability.AbilityT]
self.b = b # type: Optional[MyGame.Example.Test.TestT]
self.c = c # type: Optional[MyGame.Example.Ability.AbilityT]
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -47,8 +47,11 @@ except:
class StructOfStructsOfStructsT(object): class StructOfStructsOfStructsT(object):
# StructOfStructsOfStructsT # StructOfStructsOfStructsT
def __init__(self): def __init__(
self.a = None # type: Optional[MyGame.Example.StructOfStructs.StructOfStructsT] self,
a = None,
):
self.a = a # type: Optional[MyGame.Example.StructOfStructs.StructOfStructsT]
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -33,9 +33,13 @@ def CreateTest(builder, a, b):
class TestT(object): class TestT(object):
# TestT # TestT
def __init__(self): def __init__(
self.a = 0 # type: int self,
self.b = 0 # type: int a = 0,
b = 0,
):
self.a = a # type: int
self.b = b # type: int
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -57,8 +57,11 @@ def End(builder):
class TestSimpleTableWithEnumT(object): class TestSimpleTableWithEnumT(object):
# TestSimpleTableWithEnumT # TestSimpleTableWithEnumT
def __init__(self): def __init__(
self.color = 2 # type: int self,
color = 2,
):
self.color = color # type: int
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -256,19 +256,33 @@ except:
class TypeAliasesT(object): class TypeAliasesT(object):
# TypeAliasesT # TypeAliasesT
def __init__(self): def __init__(
self.i8 = 0 # type: int self,
self.u8 = 0 # type: int i8 = 0,
self.i16 = 0 # type: int u8 = 0,
self.u16 = 0 # type: int i16 = 0,
self.i32 = 0 # type: int u16 = 0,
self.u32 = 0 # type: int i32 = 0,
self.i64 = 0 # type: int u32 = 0,
self.u64 = 0 # type: int i64 = 0,
self.f32 = 0.0 # type: float u64 = 0,
self.f64 = 0.0 # type: float f32 = 0.0,
self.v8 = None # type: Optional[List[int]] f64 = 0.0,
self.vf64 = None # type: Optional[List[float]] v8 = None,
vf64 = None,
):
self.i8 = i8 # type: int
self.u8 = u8 # type: int
self.i16 = i16 # type: int
self.u16 = u16 # type: int
self.i32 = i32 # type: int
self.u32 = u32 # type: int
self.i64 = i64 # type: int
self.u64 = u64 # type: int
self.f32 = f32 # type: float
self.f64 = f64 # type: float
self.v8 = v8 # type: Optional[List[int]]
self.vf64 = vf64 # type: Optional[List[float]]
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -58,13 +58,21 @@ except:
class Vec3T(object): class Vec3T(object):
# Vec3T # Vec3T
def __init__(self): def __init__(
self.x = 0.0 # type: float self,
self.y = 0.0 # type: float x = 0.0,
self.z = 0.0 # type: float y = 0.0,
self.test1 = 0.0 # type: float z = 0.0,
self.test2 = 0 # type: int test1 = 0.0,
self.test3 = None # type: Optional[MyGame.Example.Test.TestT] test2 = 0,
test3 = None,
):
self.x = x # type: float
self.y = y # type: float
self.z = z # type: float
self.test1 = test1 # type: float
self.test2 = test2 # type: int
self.test3 = test3 # type: Optional[MyGame.Example.Test.TestT]
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -44,7 +44,9 @@ def End(builder):
class MonsterT(object): class MonsterT(object):
# MonsterT # MonsterT
def __init__(self): def __init__(
self,
):
pass pass
@classmethod @classmethod

View File

@@ -44,7 +44,9 @@ def End(builder):
class InParentNamespaceT(object): class InParentNamespaceT(object):
# InParentNamespaceT # InParentNamespaceT
def __init__(self): def __init__(
self,
):
pass pass
@classmethod @classmethod

View File

@@ -231,17 +231,29 @@ except:
class MonsterExtraT(object): class MonsterExtraT(object):
# MonsterExtraT # MonsterExtraT
def __init__(self): def __init__(
self.d0 = float('nan') # type: float self,
self.d1 = float('nan') # type: float d0 = float('nan'),
self.d2 = float('inf') # type: float d1 = float('nan'),
self.d3 = float('-inf') # type: float d2 = float('inf'),
self.f0 = float('nan') # type: float d3 = float('-inf'),
self.f1 = float('nan') # type: float f0 = float('nan'),
self.f2 = float('inf') # type: float f1 = float('nan'),
self.f3 = float('-inf') # type: float f2 = float('inf'),
self.dvec = None # type: Optional[List[float]] f3 = float('-inf'),
self.fvec = None # type: Optional[List[float]] dvec = None,
fvec = None,
):
self.d0 = d0 # type: float
self.d1 = d1 # type: float
self.d2 = d2 # type: float
self.d3 = d3 # type: float
self.f0 = f0 # type: float
self.f1 = f1 # type: float
self.f2 = f2 # type: float
self.f3 = f3 # type: float
self.dvec = dvec # type: Optional[List[float]]
self.fvec = fvec # type: Optional[List[float]]
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -42,6 +42,19 @@ class MonsterExtraT(object):
f3: float f3: float
dvec: typing.List[float] dvec: typing.List[float]
fvec: 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 @classmethod
def InitFromBuf(cls, buf: bytes, pos: int) -> MonsterExtraT: ... def InitFromBuf(cls, buf: bytes, pos: int) -> MonsterExtraT: ...
@classmethod @classmethod

View File

@@ -119,7 +119,9 @@ def InParentNamespaceEnd(builder):
class InParentNamespaceT(object): class InParentNamespaceT(object):
# InParentNamespaceT # InParentNamespaceT
def __init__(self): def __init__(
self,
):
pass pass
@classmethod @classmethod
@@ -184,7 +186,9 @@ def MonsterEnd(builder):
class MonsterT(object): class MonsterT(object):
# MonsterT # MonsterT
def __init__(self): def __init__(
self,
):
pass pass
@classmethod @classmethod
@@ -243,9 +247,13 @@ def CreateTest(builder, a, b):
class TestT(object): class TestT(object):
# TestT # TestT
def __init__(self): def __init__(
self.a = 0 # type: int self,
self.b = 0 # type: int a = 0,
b = 0,
):
self.a = a # type: int
self.b = b # type: int
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):
@@ -319,8 +327,11 @@ def TestSimpleTableWithEnumEnd(builder):
class TestSimpleTableWithEnumT(object): class TestSimpleTableWithEnumT(object):
# TestSimpleTableWithEnumT # TestSimpleTableWithEnumT
def __init__(self): def __init__(
self.color = 2 # type: int self,
color = 2,
):
self.color = color # type: int
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):
@@ -404,13 +415,21 @@ except:
class Vec3T(object): class Vec3T(object):
# Vec3T # Vec3T
def __init__(self): def __init__(
self.x = 0.0 # type: float self,
self.y = 0.0 # type: float x = 0.0,
self.z = 0.0 # type: float y = 0.0,
self.test1 = 0.0 # type: float z = 0.0,
self.test2 = 0 # type: int test1 = 0.0,
self.test3 = None # type: Optional[TestT] test2 = 0,
test3 = None,
):
self.x = x # type: float
self.y = y # type: float
self.z = z # type: float
self.test1 = test1 # type: float
self.test2 = test2 # type: int
self.test3 = test3 # type: Optional[TestT]
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):
@@ -472,9 +491,13 @@ def CreateAbility(builder, id, distance):
class AbilityT(object): class AbilityT(object):
# AbilityT # AbilityT
def __init__(self): def __init__(
self.id = 0 # type: int self,
self.distance = 0 # type: int id = 0,
distance = 0,
):
self.id = id # type: int
self.distance = distance # type: int
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):
@@ -554,10 +577,15 @@ except:
class StructOfStructsT(object): class StructOfStructsT(object):
# StructOfStructsT # StructOfStructsT
def __init__(self): def __init__(
self.a = None # type: Optional[AbilityT] self,
self.b = None # type: Optional[TestT] a = None,
self.c = None # type: Optional[AbilityT] b = None,
c = None,
):
self.a = a # type: Optional[AbilityT]
self.b = b # type: Optional[TestT]
self.c = c # type: Optional[AbilityT]
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):
@@ -632,8 +660,11 @@ except:
class StructOfStructsOfStructsT(object): class StructOfStructsOfStructsT(object):
# StructOfStructsOfStructsT # StructOfStructsOfStructsT
def __init__(self): def __init__(
self.a = None # type: Optional[StructOfStructsT] self,
a = None,
):
self.a = a # type: Optional[StructOfStructsT]
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):
@@ -727,10 +758,15 @@ def StatEnd(builder):
class StatT(object): class StatT(object):
# StatT # StatT
def __init__(self): def __init__(
self.id = None # type: Optional[str] self,
self.val = 0 # type: int id = None,
self.count = 0 # type: int val = 0,
count = 0,
):
self.id = id # type: Optional[str]
self.val = val # type: int
self.count = count # type: int
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):
@@ -813,8 +849,11 @@ def ReferrableEnd(builder):
class ReferrableT(object): class ReferrableT(object):
# ReferrableT # ReferrableT
def __init__(self): def __init__(
self.id = 0 # type: int self,
id = 0,
):
self.id = id # type: int
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):
@@ -1969,68 +2008,131 @@ except:
class MonsterT(object): class MonsterT(object):
# MonsterT # MonsterT
def __init__(self): def __init__(
self.pos = None # type: Optional[Vec3T] self,
self.mana = 150 # type: int pos = None,
self.hp = 100 # type: int mana = 150,
self.name = None # type: Optional[str] hp = 100,
self.inventory = None # type: Optional[List[int]] name = None,
self.color = 8 # type: int inventory = None,
self.testType = 0 # type: int color = 8,
self.test = None # type: Union[None, MonsterT, TestSimpleTableWithEnumT, MonsterT] testType = 0,
self.test4 = None # type: Optional[List[TestT]] test = None,
self.testarrayofstring = None # type: Optional[List[Optional[str]]] test4 = None,
self.testarrayoftables = None # type: Optional[List[MonsterT]] testarrayofstring = None,
self.enemy = None # type: Optional[MonsterT] testarrayoftables = None,
self.testnestedflatbuffer = None # type: Optional[List[int]] enemy = None,
self.testempty = None # type: Optional[StatT] testnestedflatbuffer = None,
self.testbool = False # type: bool testempty = None,
self.testhashs32Fnv1 = 0 # type: int testbool = False,
self.testhashu32Fnv1 = 0 # type: int testhashs32Fnv1 = 0,
self.testhashs64Fnv1 = 0 # type: int testhashu32Fnv1 = 0,
self.testhashu64Fnv1 = 0 # type: int testhashs64Fnv1 = 0,
self.testhashs32Fnv1a = 0 # type: int testhashu64Fnv1 = 0,
self.testhashu32Fnv1a = 0 # type: int testhashs32Fnv1a = 0,
self.testhashs64Fnv1a = 0 # type: int testhashu32Fnv1a = 0,
self.testhashu64Fnv1a = 0 # type: int testhashs64Fnv1a = 0,
self.testarrayofbools = None # type: Optional[List[bool]] testhashu64Fnv1a = 0,
self.testf = 3.14159 # type: float testarrayofbools = None,
self.testf2 = 3.0 # type: float testf = 3.14159,
self.testf3 = 0.0 # type: float testf2 = 3.0,
self.testarrayofstring2 = None # type: Optional[List[Optional[str]]] testf3 = 0.0,
self.testarrayofsortedstruct = None # type: Optional[List[AbilityT]] testarrayofstring2 = None,
self.flex = None # type: Optional[List[int]] testarrayofsortedstruct = None,
self.test5 = None # type: Optional[List[TestT]] flex = None,
self.vectorOfLongs = None # type: Optional[List[int]] test5 = None,
self.vectorOfDoubles = None # type: Optional[List[float]] vectorOfLongs = None,
self.parentNamespaceTest = None # type: Optional[InParentNamespaceT] vectorOfDoubles = None,
self.vectorOfReferrables = None # type: Optional[List[ReferrableT]] parentNamespaceTest = None,
self.singleWeakReference = 0 # type: int vectorOfReferrables = None,
self.vectorOfWeakReferences = None # type: Optional[List[int]] singleWeakReference = 0,
self.vectorOfStrongReferrables = None # type: Optional[List[ReferrableT]] vectorOfWeakReferences = None,
self.coOwningReference = 0 # type: int vectorOfStrongReferrables = None,
self.vectorOfCoOwningReferences = None # type: Optional[List[int]] coOwningReference = 0,
self.nonOwningReference = 0 # type: int vectorOfCoOwningReferences = None,
self.vectorOfNonOwningReferences = None # type: Optional[List[int]] nonOwningReference = 0,
self.anyUniqueType = 0 # type: int vectorOfNonOwningReferences = None,
self.anyUnique = None # type: Union[None, MonsterT, TestSimpleTableWithEnumT, MonsterT] anyUniqueType = 0,
self.anyAmbiguousType = 0 # type: int anyUnique = None,
self.anyAmbiguous = None # type: Union[None, MonsterT, MonsterT, MonsterT] anyAmbiguousType = 0,
self.vectorOfEnums = None # type: Optional[List[int]] anyAmbiguous = None,
self.signedEnum = -1 # type: int vectorOfEnums = None,
self.testrequirednestedflatbuffer = None # type: Optional[List[int]] signedEnum = -1,
self.scalarKeySortedTables = None # type: Optional[List[StatT]] testrequirednestedflatbuffer = None,
self.nativeInline = None # type: Optional[TestT] scalarKeySortedTables = None,
self.longEnumNonEnumDefault = 0 # type: int nativeInline = None,
self.longEnumNormalDefault = 2 # type: int longEnumNonEnumDefault = 0,
self.nanDefault = float('nan') # type: float longEnumNormalDefault = 2,
self.infDefault = float('inf') # type: float nanDefault = float('nan'),
self.positiveInfDefault = float('inf') # type: float infDefault = float('inf'),
self.infinityDefault = float('inf') # type: float positiveInfDefault = float('inf'),
self.positiveInfinityDefault = float('inf') # type: float infinityDefault = float('inf'),
self.negativeInfDefault = float('-inf') # type: float positiveInfinityDefault = float('inf'),
self.negativeInfinityDefault = float('-inf') # type: float negativeInfDefault = float('-inf'),
self.doubleInfDefault = float('inf') # type: float negativeInfinityDefault = float('-inf'),
doubleInfDefault = float('inf'),
):
self.pos = pos # type: Optional[Vec3T]
self.mana = mana # type: int
self.hp = hp # type: int
self.name = name # type: Optional[str]
self.inventory = inventory # type: Optional[List[int]]
self.color = color # type: int
self.testType = testType # type: int
self.test = test # type: Union[None, 'MonsterT', 'TestSimpleTableWithEnumT', 'MonsterT']
self.test4 = test4 # type: Optional[List[TestT]]
self.testarrayofstring = testarrayofstring # type: Optional[List[Optional[str]]]
self.testarrayoftables = testarrayoftables # type: Optional[List[MonsterT]]
self.enemy = enemy # type: Optional[MonsterT]
self.testnestedflatbuffer = testnestedflatbuffer # type: Optional[List[int]]
self.testempty = testempty # type: Optional[StatT]
self.testbool = testbool # type: bool
self.testhashs32Fnv1 = testhashs32Fnv1 # type: int
self.testhashu32Fnv1 = testhashu32Fnv1 # type: int
self.testhashs64Fnv1 = testhashs64Fnv1 # type: int
self.testhashu64Fnv1 = testhashu64Fnv1 # type: int
self.testhashs32Fnv1a = testhashs32Fnv1a # type: int
self.testhashu32Fnv1a = testhashu32Fnv1a # type: int
self.testhashs64Fnv1a = testhashs64Fnv1a # type: int
self.testhashu64Fnv1a = testhashu64Fnv1a # type: int
self.testarrayofbools = testarrayofbools # type: Optional[List[bool]]
self.testf = testf # type: float
self.testf2 = testf2 # type: float
self.testf3 = testf3 # type: float
self.testarrayofstring2 = testarrayofstring2 # type: Optional[List[Optional[str]]]
self.testarrayofsortedstruct = testarrayofsortedstruct # type: Optional[List[AbilityT]]
self.flex = flex # type: Optional[List[int]]
self.test5 = test5 # type: Optional[List[TestT]]
self.vectorOfLongs = vectorOfLongs # type: Optional[List[int]]
self.vectorOfDoubles = vectorOfDoubles # type: Optional[List[float]]
self.parentNamespaceTest = parentNamespaceTest # type: Optional[InParentNamespaceT]
self.vectorOfReferrables = vectorOfReferrables # type: Optional[List[ReferrableT]]
self.singleWeakReference = singleWeakReference # type: int
self.vectorOfWeakReferences = vectorOfWeakReferences # type: Optional[List[int]]
self.vectorOfStrongReferrables = vectorOfStrongReferrables # type: Optional[List[ReferrableT]]
self.coOwningReference = coOwningReference # type: int
self.vectorOfCoOwningReferences = vectorOfCoOwningReferences # type: Optional[List[int]]
self.nonOwningReference = nonOwningReference # type: int
self.vectorOfNonOwningReferences = vectorOfNonOwningReferences # type: Optional[List[int]]
self.anyUniqueType = anyUniqueType # type: int
self.anyUnique = anyUnique # type: Union[None, 'MonsterT', 'TestSimpleTableWithEnumT', 'MonsterT']
self.anyAmbiguousType = anyAmbiguousType # type: int
self.anyAmbiguous = anyAmbiguous # type: Union[None, 'MonsterT', 'MonsterT', 'MonsterT']
self.vectorOfEnums = vectorOfEnums # type: Optional[List[int]]
self.signedEnum = signedEnum # type: int
self.testrequirednestedflatbuffer = testrequirednestedflatbuffer # type: Optional[List[int]]
self.scalarKeySortedTables = scalarKeySortedTables # type: Optional[List[StatT]]
self.nativeInline = nativeInline # type: Optional[TestT]
self.longEnumNonEnumDefault = longEnumNonEnumDefault # type: int
self.longEnumNormalDefault = longEnumNormalDefault # type: int
self.nanDefault = nanDefault # type: float
self.infDefault = infDefault # type: float
self.positiveInfDefault = positiveInfDefault # type: float
self.infinityDefault = infinityDefault # type: float
self.positiveInfinityDefault = positiveInfinityDefault # type: float
self.negativeInfDefault = negativeInfDefault # type: float
self.negativeInfinityDefault = negativeInfinityDefault # type: float
self.doubleInfDefault = doubleInfDefault # type: float
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):
@@ -2708,19 +2810,33 @@ except:
class TypeAliasesT(object): class TypeAliasesT(object):
# TypeAliasesT # TypeAliasesT
def __init__(self): def __init__(
self.i8 = 0 # type: int self,
self.u8 = 0 # type: int i8 = 0,
self.i16 = 0 # type: int u8 = 0,
self.u16 = 0 # type: int i16 = 0,
self.i32 = 0 # type: int u16 = 0,
self.u32 = 0 # type: int i32 = 0,
self.i64 = 0 # type: int u32 = 0,
self.u64 = 0 # type: int i64 = 0,
self.f32 = 0.0 # type: float u64 = 0,
self.f64 = 0.0 # type: float f32 = 0.0,
self.v8 = None # type: Optional[List[int]] f64 = 0.0,
self.vf64 = None # type: Optional[List[float]] v8 = None,
vf64 = None,
):
self.i8 = i8 # type: int
self.u8 = u8 # type: int
self.i16 = i16 # type: int
self.u16 = u16 # type: int
self.i32 = i32 # type: int
self.u32 = u32 # type: int
self.i64 = i64 # type: int
self.u64 = u64 # type: int
self.f32 = f32 # type: float
self.f64 = f64 # type: float
self.v8 = v8 # type: Optional[List[int]]
self.vf64 = vf64 # type: Optional[List[float]]
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):

View File

@@ -508,47 +508,89 @@ def ScalarStuffEnd(builder):
def End(builder): def End(builder):
return ScalarStuffEnd(builder) return ScalarStuffEnd(builder)
try:
from typing import Optional
except:
pass
class ScalarStuffT(object): class ScalarStuffT(object):
# ScalarStuffT # ScalarStuffT
def __init__(self): def __init__(
self.justI8 = 0 # type: int self,
self.maybeI8 = None # type: Optional[int] justI8 = 0,
self.defaultI8 = 42 # type: int maybeI8 = None,
self.justU8 = 0 # type: int defaultI8 = 42,
self.maybeU8 = None # type: Optional[int] justU8 = 0,
self.defaultU8 = 42 # type: int maybeU8 = None,
self.justI16 = 0 # type: int defaultU8 = 42,
self.maybeI16 = None # type: Optional[int] justI16 = 0,
self.defaultI16 = 42 # type: int maybeI16 = None,
self.justU16 = 0 # type: int defaultI16 = 42,
self.maybeU16 = None # type: Optional[int] justU16 = 0,
self.defaultU16 = 42 # type: int maybeU16 = None,
self.justI32 = 0 # type: int defaultU16 = 42,
self.maybeI32 = None # type: Optional[int] justI32 = 0,
self.defaultI32 = 42 # type: int maybeI32 = None,
self.justU32 = 0 # type: int defaultI32 = 42,
self.maybeU32 = None # type: Optional[int] justU32 = 0,
self.defaultU32 = 42 # type: int maybeU32 = None,
self.justI64 = 0 # type: int defaultU32 = 42,
self.maybeI64 = None # type: Optional[int] justI64 = 0,
self.defaultI64 = 42 # type: int maybeI64 = None,
self.justU64 = 0 # type: int defaultI64 = 42,
self.maybeU64 = None # type: Optional[int] justU64 = 0,
self.defaultU64 = 42 # type: int maybeU64 = None,
self.justF32 = 0.0 # type: float defaultU64 = 42,
self.maybeF32 = None # type: Optional[float] justF32 = 0.0,
self.defaultF32 = 42.0 # type: float maybeF32 = None,
self.justF64 = 0.0 # type: float defaultF32 = 42.0,
self.maybeF64 = None # type: Optional[float] justF64 = 0.0,
self.defaultF64 = 42.0 # type: float maybeF64 = None,
self.justBool = False # type: bool defaultF64 = 42.0,
self.maybeBool = None # type: Optional[bool] justBool = False,
self.defaultBool = True # type: bool maybeBool = None,
self.justEnum = 0 # type: int defaultBool = True,
self.maybeEnum = None # type: Optional[int] justEnum = 0,
self.defaultEnum = 1 # type: int maybeEnum = None,
defaultEnum = 1,
):
self.justI8 = justI8 # type: int
self.maybeI8 = maybeI8 # type: Optional[int]
self.defaultI8 = defaultI8 # type: int
self.justU8 = justU8 # type: int
self.maybeU8 = maybeU8 # type: Optional[int]
self.defaultU8 = defaultU8 # type: int
self.justI16 = justI16 # type: int
self.maybeI16 = maybeI16 # type: Optional[int]
self.defaultI16 = defaultI16 # type: int
self.justU16 = justU16 # type: int
self.maybeU16 = maybeU16 # type: Optional[int]
self.defaultU16 = defaultU16 # type: int
self.justI32 = justI32 # type: int
self.maybeI32 = maybeI32 # type: Optional[int]
self.defaultI32 = defaultI32 # type: int
self.justU32 = justU32 # type: int
self.maybeU32 = maybeU32 # type: Optional[int]
self.defaultU32 = defaultU32 # type: int
self.justI64 = justI64 # type: int
self.maybeI64 = maybeI64 # type: Optional[int]
self.defaultI64 = defaultI64 # type: int
self.justU64 = justU64 # type: int
self.maybeU64 = maybeU64 # type: Optional[int]
self.defaultU64 = defaultU64 # type: int
self.justF32 = justF32 # type: float
self.maybeF32 = maybeF32 # type: Optional[float]
self.defaultF32 = defaultF32 # type: float
self.justF64 = justF64 # type: float
self.maybeF64 = maybeF64 # type: Optional[float]
self.defaultF64 = defaultF64 # type: float
self.justBool = justBool # type: bool
self.maybeBool = maybeBool # type: Optional[bool]
self.defaultBool = defaultBool # type: bool
self.justEnum = justEnum # type: int
self.maybeEnum = maybeEnum # type: Optional[int]
self.defaultEnum = defaultEnum # type: int
@classmethod @classmethod
def InitFromBuf(cls, buf, pos): def InitFromBuf(cls, buf, pos):