Better python generated code naming (#6336)

* Remove a lot of redundancy from the Python generated code.

Update tutorial to reflect new Python generated code.

* Add aliases for newly deprecated Python generated methods.

This should help with backwards compatibility.

* Fix incorrect names in deprecated comments.
This commit is contained in:
Richard A Hofer
2021-01-28 15:35:37 -05:00
committed by GitHub
parent 6effe431bb
commit 13d9e35858
17 changed files with 1000 additions and 496 deletions

View File

@@ -10,13 +10,17 @@ class TestSimpleTableWithEnum(object):
__slots__ = ['_tab']
@classmethod
def GetRootAsTestSimpleTableWithEnum(cls, buf, offset=0):
def GetRootAs(cls, buf, offset=0):
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
x = TestSimpleTableWithEnum()
x.Init(buf, n + offset)
return x
@classmethod
def GetRootAsTestSimpleTableWithEnum(cls, buf, offset=0):
"""This method is deprecated. Please switch to GetRootAs."""
return cls.GetRootAs(buf, offset)
@classmethod
def TestSimpleTableWithEnumBufferHasIdentifier(cls, buf, offset, size_prefixed=False):
return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x4D\x4F\x4E\x53", size_prefixed=size_prefixed)
@@ -31,10 +35,18 @@ class TestSimpleTableWithEnum(object):
return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos)
return 2
def TestSimpleTableWithEnumStart(builder): builder.StartObject(1)
def TestSimpleTableWithEnumAddColor(builder, color): builder.PrependUint8Slot(0, color, 2)
def TestSimpleTableWithEnumEnd(builder): return builder.EndObject()
def Start(builder): builder.StartObject(1)
def TestSimpleTableWithEnumStart(builder):
"""This method is deprecated. Please switch to Start."""
return Start(builder)
def AddColor(builder, color): builder.PrependUint8Slot(0, color, 2)
def TestSimpleTableWithEnumAddColor(builder, color):
"""This method is deprecated. Please switch to AddColor."""
return AddColor(builder, color)
def End(builder): return builder.EndObject()
def TestSimpleTableWithEnumEnd(builder):
"""This method is deprecated. Please switch to End."""
return End(builder)
class TestSimpleTableWithEnumT(object):
@@ -62,7 +74,7 @@ class TestSimpleTableWithEnumT(object):
# TestSimpleTableWithEnumT
def Pack(self, builder):
TestSimpleTableWithEnumStart(builder)
TestSimpleTableWithEnumAddColor(builder, self.color)
testSimpleTableWithEnum = TestSimpleTableWithEnumEnd(builder)
Start(builder)
AddColor(builder, self.color)
testSimpleTableWithEnum = End(builder)
return testSimpleTableWithEnum