google / google/flatbuffers

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

Open
#8,715 1 comment 1 reaction 0 assignees View on GitHub
pr-requested python
Dominant language
C++
Stars
26.5k
Forks
3.7k
PR merge metrics
No merged PRs in 30d

Description

### 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
```fbs
table TableFoo {
field1 :uint8 ;
field2 :string ;
}

table TableBoo {
table1 :TableFoo ;
}
```

produces

```python
# ...

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

# ...
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.