flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

[Python] Object API breaks for structs will all-caps names

Open gtaska opened this issue 1 year ago • 0 comments

Affected Language: Python Compiler Version: flatc version 23.5.26 Operating System: Windows 10

fbs file (test.fbs)

struct ALLCAPS
{
    data  : uint8;
}

Compiler command line

flatc --python --gen-object-api test.fbs

Issue

In the generated Python code, the object API uses the wrong function name to create the 'ALLCAPS' struct in the Pack() call.

Function to create the ALLCAPS structure:

def CreateALLCAPS(builder, data):
    builder.Prep(1, 1)
    builder.PrependUint8(data)
    return builder.Offset()

Generated Object API:

class ALLCAPST(object):
    ...
    # ALLCAPST
    def Pack(self, builder):
        return CreateAllcaps(builder, self.data)

Regardless of ones stance about whether or not name-mangling should be applied to ensure uniform camel/snake case, the generated code should be self-consistent.

Either

  • def CreateALLCAPS(builder, data): should be def CreateAllcaps(builder, data):, or
  • return CreateAllcaps(builder, self.data) should be return CreateALLCAPS(builder, self.data)

gtaska avatar Oct 11 '23 19:10 gtaska