google / flatbuffers

FlatBuffers: Memory Efficient Serialization Library
https://flatbuffers.dev/
Apache License 2.0
22.52k stars 3.19k forks source link

Add prefix to import path when referencing generated modules [Python, flatc 24.3.25] #8345

Open c92s opened 1 week ago

c92s commented 1 week ago

Imagine, we have the following schema file:

namespace mydata;

table Data {
    value:string;
    size:uint;
}

table Element {
    data:Data;
}

root_type Element;

Running flatc --python -o . example.fbs --python-typing generates a directory mydata/ with an __init__.py, a Data.py and a Element.py.

As the Element references the Data table, it imports the class from that file:

# mydata/Element.py

import flatbuffers
from flatbuffers.compat import import_numpy
from typing import Any
from mydata.Data import Data
from typing import Optional
...

Is there a way, to modify the import statement from mydata.Data import Data to, e.g. from mylibray.mydata.Data import Data, without modifying the original schema files?