mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-10 07:06:26 +00:00
[Python] Render enums as Python IntEnum (#8145)
This allows enums to be type check with mypy. They will still behave like ints -> > IntEnum is the same as Enum, > but its members are also integers and can be used anywhere > that an integer can be used. > If any integer operation is performed with an IntEnum member, > the resulting value loses its enumeration status. https://docs.python.org/3/library/enum.html#enum.IntEnum Only if the --python-typing flag is set.
This commit is contained in:
@@ -12,13 +12,13 @@ def AnyCreator(unionType, table):
|
||||
from flatbuffers.table import Table
|
||||
if not isinstance(table, Table):
|
||||
return None
|
||||
if unionType == Any().Monster:
|
||||
if unionType == Any.Monster:
|
||||
import MyGame.Example.Monster
|
||||
return MyGame.Example.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos)
|
||||
if unionType == Any().TestSimpleTableWithEnum:
|
||||
if unionType == Any.TestSimpleTableWithEnum:
|
||||
import MyGame.Example.TestSimpleTableWithEnum
|
||||
return MyGame.Example.TestSimpleTableWithEnum.TestSimpleTableWithEnumT.InitFromBuf(table.Bytes, table.Pos)
|
||||
if unionType == Any().MyGame_Example2_Monster:
|
||||
if unionType == Any.MyGame_Example2_Monster:
|
||||
import MyGame.Example2.Monster
|
||||
return MyGame.Example2.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos)
|
||||
return None
|
||||
|
||||
@@ -12,13 +12,13 @@ def AnyAmbiguousAliasesCreator(unionType, table):
|
||||
from flatbuffers.table import Table
|
||||
if not isinstance(table, Table):
|
||||
return None
|
||||
if unionType == AnyAmbiguousAliases().M1:
|
||||
if unionType == AnyAmbiguousAliases.M1:
|
||||
import MyGame.Example.Monster
|
||||
return MyGame.Example.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos)
|
||||
if unionType == AnyAmbiguousAliases().M2:
|
||||
if unionType == AnyAmbiguousAliases.M2:
|
||||
import MyGame.Example.Monster
|
||||
return MyGame.Example.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos)
|
||||
if unionType == AnyAmbiguousAliases().M3:
|
||||
if unionType == AnyAmbiguousAliases.M3:
|
||||
import MyGame.Example.Monster
|
||||
return MyGame.Example.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos)
|
||||
return None
|
||||
|
||||
@@ -12,13 +12,13 @@ def AnyUniqueAliasesCreator(unionType, table):
|
||||
from flatbuffers.table import Table
|
||||
if not isinstance(table, Table):
|
||||
return None
|
||||
if unionType == AnyUniqueAliases().M:
|
||||
if unionType == AnyUniqueAliases.M:
|
||||
import MyGame.Example.Monster
|
||||
return MyGame.Example.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos)
|
||||
if unionType == AnyUniqueAliases().TS:
|
||||
if unionType == AnyUniqueAliases.TS:
|
||||
import MyGame.Example.TestSimpleTableWithEnum
|
||||
return MyGame.Example.TestSimpleTableWithEnum.TestSimpleTableWithEnumT.InitFromBuf(table.Bytes, table.Pos)
|
||||
if unionType == AnyUniqueAliases().M2:
|
||||
if unionType == AnyUniqueAliases.M2:
|
||||
import MyGame.Example2.Monster
|
||||
return MyGame.Example2.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos)
|
||||
return None
|
||||
|
||||
@@ -11,10 +11,10 @@ def AnyCreator(unionType, table):
|
||||
from flatbuffers.table import Table
|
||||
if not isinstance(table, Table):
|
||||
return None
|
||||
if unionType == Any().Vec3:
|
||||
if unionType == Any.Vec3:
|
||||
import MyGame.Example.NestedUnion.Vec3
|
||||
return MyGame.Example.NestedUnion.Vec3.Vec3T.InitFromBuf(table.Bytes, table.Pos)
|
||||
if unionType == Any().TestSimpleTableWithEnum:
|
||||
if unionType == Any.TestSimpleTableWithEnum:
|
||||
import MyGame.Example.NestedUnion.TestSimpleTableWithEnum
|
||||
return MyGame.Example.NestedUnion.TestSimpleTableWithEnum.TestSimpleTableWithEnumT.InitFromBuf(table.Bytes, table.Pos)
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user