-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
23.5.8's Python code generator creates import statements that break existing projects using 23.3.3 or earlier #7951
Comments
I'll defer to @maxburke since I don't really do python much, but it seems like this line https://github.com/google/flatbuffers/blob/master/src/idl_gen_python.cpp#L278 and others like it are the issue? I think the lack of @stewartmiles could you remove those instances of the |
@dbaileychess I ended up doing a local workaround which is pretty similar. I patched the generated code to replace |
I can get diff --git a/src/idl_gen_python.cpp b/src/idl_gen_python.cpp
index 72b54604..ff535d15 100644
--- a/src/idl_gen_python.cpp
+++ b/src/idl_gen_python.cpp
@@ -275,7 +275,7 @@ class PythonGenerator : public BaseGenerator {
code += namer_.Method(field);
const ImportMapEntry import_entry = {
- "." + GenPackageReference(field.value.type), TypeName(field)
+ GenPackageReference(field.value.type), TypeName(field)
};
if (parser_.opts.python_typing) {
@@ -337,7 +337,7 @@ class PythonGenerator : public BaseGenerator {
code += namer_.Method(field) + "(self)";
const ImportMapEntry import_entry = {
- "." + GenPackageReference(field.value.type), TypeName(field)
+ GenPackageReference(field.value.type), TypeName(field)
};
if (parser_.opts.python_typing) {
@@ -446,7 +446,7 @@ class PythonGenerator : public BaseGenerator {
GenReceiver(struct_def, code_ptr);
code += namer_.Method(field);
const ImportMapEntry import_entry = {
- "." + GenPackageReference(field.value.type), TypeName(field)
+ GenPackageReference(field.value.type), TypeName(field)
};
if (parser_.opts.python_typing) {
@@ -570,7 +570,7 @@ class PythonGenerator : public BaseGenerator {
std::string qualified_name = NestedFlatbufferType(unqualified_name);
if (qualified_name.empty()) { qualified_name = nested->constant; }
- const ImportMapEntry import_entry = { "." + qualified_name,
+ const ImportMapEntry import_entry = { qualified_name,
unqualified_name };
auto &code = *code_ptr; |
* Don't generate types unless --python-typing specified Fixes google#7944 * Fix incorrect import statements Fixes google#7951 * Fix $PYTHONPATH in PythonTest.sh Regressed from google#7529 * PythonTest: fail if something goes wrong GitHub Actions runs `bash PythonTest.sh`, and thus failures were not visible. * Build flatc for Python tests * Regenerate codes --------- Co-authored-by: Derek Bailey <derekbailey@google.com>
* Don't generate types unless --python-typing specified Fixes google#7944 * Fix incorrect import statements Fixes google#7951 * Fix $PYTHONPATH in PythonTest.sh Regressed from google#7529 * PythonTest: fail if something goes wrong GitHub Actions runs `bash PythonTest.sh`, and thus failures were not visible. * Build flatc for Python tests * Regenerate codes --------- Co-authored-by: Derek Bailey <derekbailey@google.com>
#7858 changes the way Python imports are generated from, for example:
to:
This breaks packages where the root is the generated flatbuffers package name. For example, we have code that generates Python FlatBuffers code from TensorFlow Lite's schema that places all code into a top-level Python package called
tflite
i.e given the file structure:Where the code is generated using a command line like this:
This yields a load of generated files:
Finally, when importing one of these modules that transitively imports another module the problem pops up:
produces:
@maxburke and @dbaileychess thoughts on a fix?
The text was updated successfully, but these errors were encountered: