flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

[Python] '--python-no-type-prefix-suffix' and '--gen-object-api' are incompatible

Open souryavarenya opened this issue 3 months ago • 0 comments

Description

When using --python-no-type-prefix-suffix and --gen-object-api flags for python codegen, the Pack method of the object API is broken as it still calls the prefixed method.

While this looks fixable, maybe --python-no-type-prefix-suffix is not so good to use in general.

Minimal example

schema

table TableFoo {
    field1  :uint8      ;
    field2  :string     ;
}

table TableBoo {
    table1  :TableFoo   ;
}

produces

# ...

def Start(builder: flatbuffers.Builder):  # `--python-no-type-prefix-suffix` flag?
    builder.StartObject(1)                # generates multiple conflicting Start() functions 

def AddTable1(builder: flatbuffers.Builder, table1: int):
    builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(table1), 0)

def End(builder: flatbuffers.Builder) -> int:
    return builder.EndObject()

# ...
class TableBooT(object):

    # ...

    # TableBooT
    def Pack(self, builder):
        if self.table1 is not None:
            table1 = self.table1.Pack(builder)
        TableBooStart(builder)                                   # <-- no good
        if self.table1 is not None:
            TableBooAddTable1(builder, table1)                   # <-- no good
        tableBoo = TableBooEnd(builder)                          # <-- no good
        return tableBoo


# ...

souryavarenya avatar Sep 30 '25 15:09 souryavarenya