mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-06 21:37:36 +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:
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: ...
|
||||
|
||||
Reference in New Issue
Block a user