mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-11 23:40:57 +00:00
[Python] Generate .pyi stub files when --python-typing is on. (#8312)
* [Python] Generate `.pyi` stub files when `--python-typing` is on. To support this change, the following modifications were made: - added a new option to disable `numpy` helpers generation; - added a new flag to control the target Python version: `--python-version` can be one of the following: - `0.x.x` – compatible with any Python version; - `2.x.x` – compatible with Python 2; - `3.x.x` – compatible with Python 3. - added codegen utilities for Python; - added a note that the generated .py file is empty. * [Python] Update Bazel build rules. * [Python] Update Bazel build rules. * [Python] Run buildifier on BUILD.bazel files. --------- Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
50
tests/MyGame/Example/ArrayStruct.pyi
Normal file
50
tests/MyGame/Example/ArrayStruct.pyi
Normal file
@@ -0,0 +1,50 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import flatbuffers
|
||||
import numpy as np
|
||||
|
||||
import flatbuffers
|
||||
import typing
|
||||
from MyGame.Example.ArrayStruct import ArrayStruct
|
||||
from MyGame.Example.NestedStruct import NestedStruct, NestedStructT
|
||||
from MyGame.Example.TestEnum import TestEnum
|
||||
|
||||
uoffset: typing.TypeAlias = flatbuffers.number_types.UOffsetTFlags.py_type
|
||||
|
||||
class ArrayStruct(object):
|
||||
@classmethod
|
||||
def SizeOf(cls) -> int: ...
|
||||
|
||||
def Init(self, buf: bytes, pos: int) -> None: ...
|
||||
def A(self) -> float: ...
|
||||
def B(self, i: int) -> typing.List[int]: ...
|
||||
def BAsNumpy(self) -> np.ndarray: ...
|
||||
def BLength(self) -> int: ...
|
||||
def BIsNone(self) -> bool: ...
|
||||
def C(self) -> int: ...
|
||||
def D(self, i: int) -> NestedStruct | None: ...
|
||||
def DLength(self) -> int: ...
|
||||
def DIsNone(self) -> bool: ...
|
||||
def E(self) -> int: ...
|
||||
def F(self, i: int) -> typing.List[int]: ...
|
||||
def FAsNumpy(self) -> np.ndarray: ...
|
||||
def FLength(self) -> int: ...
|
||||
def FIsNone(self) -> bool: ...
|
||||
class ArrayStructT(object):
|
||||
a: float
|
||||
b: typing.List[int]
|
||||
c: int
|
||||
d: typing.List[NestedStructT]
|
||||
e: int
|
||||
f: typing.List[int]
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf: bytes, pos: int) -> ArrayStructT: ...
|
||||
@classmethod
|
||||
def InitFromPackedBuf(cls, buf: bytes, pos: int = 0) -> ArrayStructT: ...
|
||||
@classmethod
|
||||
def InitFromObj(cls, arrayStruct: ArrayStruct) -> ArrayStructT: ...
|
||||
def _UnPack(self, arrayStruct: ArrayStruct) -> None: ...
|
||||
def Pack(self, builder: flatbuffers.Builder) -> None: ...
|
||||
|
||||
def CreateArrayStruct(builder: flatbuffers.Builder, a: float, b: int, c: int, d_a: int, d_b: typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C], d_c: typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C], d_d: int, e: int, f: int) -> uoffset: ...
|
||||
|
||||
37
tests/MyGame/Example/ArrayTable.pyi
Normal file
37
tests/MyGame/Example/ArrayTable.pyi
Normal file
@@ -0,0 +1,37 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import flatbuffers
|
||||
import numpy as np
|
||||
|
||||
import flatbuffers
|
||||
import typing
|
||||
from MyGame.Example.ArrayStruct import ArrayStruct, ArrayStructT
|
||||
from MyGame.Example.ArrayTable import ArrayTable
|
||||
|
||||
uoffset: typing.TypeAlias = flatbuffers.number_types.UOffsetTFlags.py_type
|
||||
|
||||
class ArrayTable(object):
|
||||
@classmethod
|
||||
def GetRootAs(cls, buf: bytes, offset: int) -> ArrayTable: ...
|
||||
@classmethod
|
||||
def GetRootAsArrayTable(cls, buf: bytes, offset: int) -> ArrayTable: ...
|
||||
@classmethod
|
||||
def ArrayTableBufferHasIdentifier(cls, buf: bytes, offset: int, size_prefixed: bool) -> bool: ...
|
||||
def Init(self, buf: bytes, pos: int) -> None: ...
|
||||
def A(self) -> ArrayStruct | None: ...
|
||||
class ArrayTableT(object):
|
||||
a: ArrayStructT | None
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf: bytes, pos: int) -> ArrayTableT: ...
|
||||
@classmethod
|
||||
def InitFromPackedBuf(cls, buf: bytes, pos: int = 0) -> ArrayTableT: ...
|
||||
@classmethod
|
||||
def InitFromObj(cls, arrayTable: ArrayTable) -> ArrayTableT: ...
|
||||
def _UnPack(self, arrayTable: ArrayTable) -> None: ...
|
||||
def Pack(self, builder: flatbuffers.Builder) -> None: ...
|
||||
def ArrayTableStart(builder: flatbuffers.Builder) -> None: ...
|
||||
def Start(builder: flatbuffers.Builder) -> None: ...
|
||||
def ArrayTableAddA(builder: flatbuffers.Builder, a: uoffset) -> None: ...
|
||||
def ArrayTableEnd(builder: flatbuffers.Builder) -> uoffset: ...
|
||||
def End(builder: flatbuffers.Builder) -> uoffset: ...
|
||||
|
||||
46
tests/MyGame/Example/NestedStruct.pyi
Normal file
46
tests/MyGame/Example/NestedStruct.pyi
Normal file
@@ -0,0 +1,46 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import flatbuffers
|
||||
import numpy as np
|
||||
|
||||
import flatbuffers
|
||||
import typing
|
||||
from MyGame.Example.NestedStruct import NestedStruct
|
||||
from MyGame.Example.TestEnum import TestEnum
|
||||
|
||||
uoffset: typing.TypeAlias = flatbuffers.number_types.UOffsetTFlags.py_type
|
||||
|
||||
class NestedStruct(object):
|
||||
@classmethod
|
||||
def SizeOf(cls) -> int: ...
|
||||
|
||||
def Init(self, buf: bytes, pos: int) -> None: ...
|
||||
def A(self, i: int) -> typing.List[int]: ...
|
||||
def AAsNumpy(self) -> np.ndarray: ...
|
||||
def ALength(self) -> int: ...
|
||||
def AIsNone(self) -> bool: ...
|
||||
def B(self) -> typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C]: ...
|
||||
def C(self, i: int) -> typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C]: ...
|
||||
def CAsNumpy(self) -> np.ndarray: ...
|
||||
def CLength(self) -> int: ...
|
||||
def CIsNone(self) -> bool: ...
|
||||
def D(self, i: int) -> typing.List[int]: ...
|
||||
def DAsNumpy(self) -> np.ndarray: ...
|
||||
def DLength(self) -> int: ...
|
||||
def DIsNone(self) -> bool: ...
|
||||
class NestedStructT(object):
|
||||
a: typing.List[int]
|
||||
b: typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C]
|
||||
c: typing.List[typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C]]
|
||||
d: typing.List[int]
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf: bytes, pos: int) -> NestedStructT: ...
|
||||
@classmethod
|
||||
def InitFromPackedBuf(cls, buf: bytes, pos: int = 0) -> NestedStructT: ...
|
||||
@classmethod
|
||||
def InitFromObj(cls, nestedStruct: NestedStruct) -> NestedStructT: ...
|
||||
def _UnPack(self, nestedStruct: NestedStruct) -> None: ...
|
||||
def Pack(self, builder: flatbuffers.Builder) -> None: ...
|
||||
|
||||
def CreateNestedStruct(builder: flatbuffers.Builder, a: int, b: typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C], c: typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C], d: int) -> uoffset: ...
|
||||
|
||||
20
tests/MyGame/Example/NestedUnion/Any.pyi
Normal file
20
tests/MyGame/Example/NestedUnion/Any.pyi
Normal file
@@ -0,0 +1,20 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import flatbuffers
|
||||
import numpy as np
|
||||
|
||||
import flatbuffers
|
||||
import typing
|
||||
from MyGame.Example.NestedUnion.Any import Any
|
||||
from MyGame.Example.NestedUnion.TestSimpleTableWithEnum import TestSimpleTableWithEnum
|
||||
from MyGame.Example.NestedUnion.Vec3 import Vec3
|
||||
from flatbuffers import table
|
||||
|
||||
uoffset: typing.TypeAlias = flatbuffers.number_types.UOffsetTFlags.py_type
|
||||
|
||||
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]: ...
|
||||
|
||||
15
tests/MyGame/Example/NestedUnion/Color.pyi
Normal file
15
tests/MyGame/Example/NestedUnion/Color.pyi
Normal file
@@ -0,0 +1,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import flatbuffers
|
||||
import numpy as np
|
||||
|
||||
import flatbuffers
|
||||
import typing
|
||||
|
||||
uoffset: typing.TypeAlias = flatbuffers.number_types.UOffsetTFlags.py_type
|
||||
|
||||
class Color(object):
|
||||
Red: int
|
||||
Green: int
|
||||
Blue: int
|
||||
|
||||
47
tests/MyGame/Example/NestedUnion/NestedUnionTest.pyi
Normal file
47
tests/MyGame/Example/NestedUnion/NestedUnionTest.pyi
Normal file
@@ -0,0 +1,47 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import flatbuffers
|
||||
import numpy as np
|
||||
|
||||
import flatbuffers
|
||||
import typing
|
||||
from MyGame.Example.NestedUnion.Any import Any
|
||||
from MyGame.Example.NestedUnion.NestedUnionTest import NestedUnionTest
|
||||
from MyGame.Example.NestedUnion.TestSimpleTableWithEnum import TestSimpleTableWithEnumT
|
||||
from MyGame.Example.NestedUnion.Vec3 import Vec3T
|
||||
from flatbuffers import table
|
||||
|
||||
uoffset: typing.TypeAlias = flatbuffers.number_types.UOffsetTFlags.py_type
|
||||
|
||||
class NestedUnionTest(object):
|
||||
@classmethod
|
||||
def GetRootAs(cls, buf: bytes, offset: int) -> NestedUnionTest: ...
|
||||
@classmethod
|
||||
def GetRootAsNestedUnionTest(cls, buf: bytes, offset: int) -> NestedUnionTest: ...
|
||||
def Init(self, buf: bytes, pos: int) -> None: ...
|
||||
def Name(self) -> str | None: ...
|
||||
def DataType(self) -> typing.Literal[Any.NONE, Any.Vec3, Any.TestSimpleTableWithEnum]: ...
|
||||
def Data(self) -> table.Table | None: ...
|
||||
def Id(self) -> int: ...
|
||||
class NestedUnionTestT(object):
|
||||
name: str | None
|
||||
dataType: typing.Literal[Any.NONE, Any.Vec3, Any.TestSimpleTableWithEnum]
|
||||
data: typing.Union[None, Vec3T, TestSimpleTableWithEnumT]
|
||||
id: int
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf: bytes, pos: int) -> NestedUnionTestT: ...
|
||||
@classmethod
|
||||
def InitFromPackedBuf(cls, buf: bytes, pos: int = 0) -> NestedUnionTestT: ...
|
||||
@classmethod
|
||||
def InitFromObj(cls, nestedUnionTest: NestedUnionTest) -> NestedUnionTestT: ...
|
||||
def _UnPack(self, nestedUnionTest: NestedUnionTest) -> None: ...
|
||||
def Pack(self, builder: flatbuffers.Builder) -> None: ...
|
||||
def NestedUnionTestStart(builder: flatbuffers.Builder) -> None: ...
|
||||
def Start(builder: flatbuffers.Builder) -> None: ...
|
||||
def NestedUnionTestAddName(builder: flatbuffers.Builder, name: uoffset) -> None: ...
|
||||
def NestedUnionTestAddDataType(builder: flatbuffers.Builder, dataType: typing.Literal[Any.NONE, Any.Vec3, Any.TestSimpleTableWithEnum]) -> None: ...
|
||||
def NestedUnionTestAddData(builder: flatbuffers.Builder, data: uoffset) -> None: ...
|
||||
def NestedUnionTestAddId(builder: flatbuffers.Builder, id: int) -> None: ...
|
||||
def NestedUnionTestEnd(builder: flatbuffers.Builder) -> uoffset: ...
|
||||
def End(builder: flatbuffers.Builder) -> uoffset: ...
|
||||
|
||||
32
tests/MyGame/Example/NestedUnion/Test.pyi
Normal file
32
tests/MyGame/Example/NestedUnion/Test.pyi
Normal file
@@ -0,0 +1,32 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import flatbuffers
|
||||
import numpy as np
|
||||
|
||||
import flatbuffers
|
||||
import typing
|
||||
from MyGame.Example.NestedUnion.Test import Test
|
||||
|
||||
uoffset: typing.TypeAlias = flatbuffers.number_types.UOffsetTFlags.py_type
|
||||
|
||||
class Test(object):
|
||||
@classmethod
|
||||
def SizeOf(cls) -> int: ...
|
||||
|
||||
def Init(self, buf: bytes, pos: int) -> None: ...
|
||||
def A(self) -> int: ...
|
||||
def B(self) -> int: ...
|
||||
class TestT(object):
|
||||
a: int
|
||||
b: int
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf: bytes, pos: int) -> TestT: ...
|
||||
@classmethod
|
||||
def InitFromPackedBuf(cls, buf: bytes, pos: int = 0) -> TestT: ...
|
||||
@classmethod
|
||||
def InitFromObj(cls, test: Test) -> TestT: ...
|
||||
def _UnPack(self, test: Test) -> None: ...
|
||||
def Pack(self, builder: flatbuffers.Builder) -> None: ...
|
||||
|
||||
def CreateTest(builder: flatbuffers.Builder, a: int, b: int) -> uoffset: ...
|
||||
|
||||
35
tests/MyGame/Example/NestedUnion/TestSimpleTableWithEnum.pyi
Normal file
35
tests/MyGame/Example/NestedUnion/TestSimpleTableWithEnum.pyi
Normal file
@@ -0,0 +1,35 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import flatbuffers
|
||||
import numpy as np
|
||||
|
||||
import flatbuffers
|
||||
import typing
|
||||
from MyGame.Example.NestedUnion.Color import Color
|
||||
from MyGame.Example.NestedUnion.TestSimpleTableWithEnum import TestSimpleTableWithEnum
|
||||
|
||||
uoffset: typing.TypeAlias = flatbuffers.number_types.UOffsetTFlags.py_type
|
||||
|
||||
class TestSimpleTableWithEnum(object):
|
||||
@classmethod
|
||||
def GetRootAs(cls, buf: bytes, offset: int) -> TestSimpleTableWithEnum: ...
|
||||
@classmethod
|
||||
def GetRootAsTestSimpleTableWithEnum(cls, buf: bytes, offset: int) -> TestSimpleTableWithEnum: ...
|
||||
def Init(self, buf: bytes, pos: int) -> None: ...
|
||||
def Color(self) -> typing.Literal[Color.Red, Color.Green, Color.Blue]: ...
|
||||
class TestSimpleTableWithEnumT(object):
|
||||
color: typing.Literal[Color.Red, Color.Green, Color.Blue]
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf: bytes, pos: int) -> TestSimpleTableWithEnumT: ...
|
||||
@classmethod
|
||||
def InitFromPackedBuf(cls, buf: bytes, pos: int = 0) -> TestSimpleTableWithEnumT: ...
|
||||
@classmethod
|
||||
def InitFromObj(cls, testSimpleTableWithEnum: TestSimpleTableWithEnum) -> TestSimpleTableWithEnumT: ...
|
||||
def _UnPack(self, testSimpleTableWithEnum: TestSimpleTableWithEnum) -> None: ...
|
||||
def Pack(self, builder: flatbuffers.Builder) -> None: ...
|
||||
def TestSimpleTableWithEnumStart(builder: flatbuffers.Builder) -> None: ...
|
||||
def Start(builder: flatbuffers.Builder) -> None: ...
|
||||
def TestSimpleTableWithEnumAddColor(builder: flatbuffers.Builder, color: typing.Literal[Color.Red, Color.Green, Color.Blue]) -> None: ...
|
||||
def TestSimpleTableWithEnumEnd(builder: flatbuffers.Builder) -> uoffset: ...
|
||||
def End(builder: flatbuffers.Builder) -> uoffset: ...
|
||||
|
||||
51
tests/MyGame/Example/NestedUnion/Vec3.pyi
Normal file
51
tests/MyGame/Example/NestedUnion/Vec3.pyi
Normal file
@@ -0,0 +1,51 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import flatbuffers
|
||||
import numpy as np
|
||||
|
||||
import flatbuffers
|
||||
import typing
|
||||
from MyGame.Example.NestedUnion.Color import Color
|
||||
from MyGame.Example.NestedUnion.Test import Test, TestT
|
||||
from MyGame.Example.NestedUnion.Vec3 import Vec3
|
||||
|
||||
uoffset: typing.TypeAlias = flatbuffers.number_types.UOffsetTFlags.py_type
|
||||
|
||||
class Vec3(object):
|
||||
@classmethod
|
||||
def GetRootAs(cls, buf: bytes, offset: int) -> Vec3: ...
|
||||
@classmethod
|
||||
def GetRootAsVec3(cls, buf: bytes, offset: int) -> Vec3: ...
|
||||
def Init(self, buf: bytes, pos: int) -> None: ...
|
||||
def X(self) -> float: ...
|
||||
def Y(self) -> float: ...
|
||||
def Z(self) -> float: ...
|
||||
def Test1(self) -> float: ...
|
||||
def Test2(self) -> typing.Literal[Color.Red, Color.Green, Color.Blue]: ...
|
||||
def Test3(self) -> Test | None: ...
|
||||
class Vec3T(object):
|
||||
x: float
|
||||
y: float
|
||||
z: float
|
||||
test1: float
|
||||
test2: typing.Literal[Color.Red, Color.Green, Color.Blue]
|
||||
test3: TestT | None
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf: bytes, pos: int) -> Vec3T: ...
|
||||
@classmethod
|
||||
def InitFromPackedBuf(cls, buf: bytes, pos: int = 0) -> Vec3T: ...
|
||||
@classmethod
|
||||
def InitFromObj(cls, vec3: Vec3) -> Vec3T: ...
|
||||
def _UnPack(self, vec3: Vec3) -> None: ...
|
||||
def Pack(self, builder: flatbuffers.Builder) -> None: ...
|
||||
def Vec3Start(builder: flatbuffers.Builder) -> None: ...
|
||||
def Start(builder: flatbuffers.Builder) -> None: ...
|
||||
def Vec3AddX(builder: flatbuffers.Builder, x: float) -> None: ...
|
||||
def Vec3AddY(builder: flatbuffers.Builder, y: float) -> None: ...
|
||||
def Vec3AddZ(builder: flatbuffers.Builder, z: float) -> None: ...
|
||||
def Vec3AddTest1(builder: flatbuffers.Builder, test1: float) -> None: ...
|
||||
def Vec3AddTest2(builder: flatbuffers.Builder, test2: typing.Literal[Color.Red, Color.Green, Color.Blue]) -> None: ...
|
||||
def Vec3AddTest3(builder: flatbuffers.Builder, test3: uoffset) -> None: ...
|
||||
def Vec3End(builder: flatbuffers.Builder) -> uoffset: ...
|
||||
def End(builder: flatbuffers.Builder) -> uoffset: ...
|
||||
|
||||
15
tests/MyGame/Example/TestEnum.pyi
Normal file
15
tests/MyGame/Example/TestEnum.pyi
Normal file
@@ -0,0 +1,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import flatbuffers
|
||||
import numpy as np
|
||||
|
||||
import flatbuffers
|
||||
import typing
|
||||
|
||||
uoffset: typing.TypeAlias = flatbuffers.number_types.UOffsetTFlags.py_type
|
||||
|
||||
class TestEnum(object):
|
||||
A: int
|
||||
B: int
|
||||
C: int
|
||||
|
||||
Reference in New Issue
Block a user