From dfd92124aa55e5d1b9691125682ceb1bf2d2b757 Mon Sep 17 00:00:00 2001 From: Aaron Barany Date: Mon, 23 Jun 2025 12:00:37 -0700 Subject: [PATCH] Avoid outputting Python files for already generated types (#8500) This may overwrite types that have already been generated and can create unwanted empty files. Fixes #8490 --- src/idl_gen_python.cpp | 11 ++++------- tests/FromInclude.py | 5 ----- tests/MyGame/OtherNameSpace/FromInclude.py | 5 ----- tests/MyGame/OtherNameSpace/TableB.py | 5 ----- tests/MyGame/OtherNameSpace/Unused.py | 5 ----- tests/MyGame/OtherNameSpace/__init__.py | 0 tests/TableA.py | 5 ----- tests/__init__.py | 0 8 files changed, 4 insertions(+), 32 deletions(-) delete mode 100644 tests/FromInclude.py delete mode 100644 tests/MyGame/OtherNameSpace/FromInclude.py delete mode 100644 tests/MyGame/OtherNameSpace/TableB.py delete mode 100644 tests/MyGame/OtherNameSpace/Unused.py delete mode 100644 tests/MyGame/OtherNameSpace/__init__.py delete mode 100644 tests/TableA.py delete mode 100644 tests/__init__.py diff --git a/src/idl_gen_python.cpp b/src/idl_gen_python.cpp index 1c814cd53..fc51147ce 100644 --- a/src/idl_gen_python.cpp +++ b/src/idl_gen_python.cpp @@ -2686,14 +2686,11 @@ class PythonGenerator : public BaseGenerator { bool SaveType(const std::string &defname, const Namespace &ns, const std::string &classcode, const ImportMap &imports, const std::string &mod, bool needs_imports) const { + if (classcode.empty()) return true; + std::string code = ""; - if (classcode.empty()) { - BeginFile(LastNamespacePart(ns), false, &code, "", {}); - code += "# NOTE " + defname + " does not declare any structs or enums\n"; - } else { - BeginFile(LastNamespacePart(ns), needs_imports, &code, mod, imports); - code += classcode; - } + BeginFile(LastNamespacePart(ns), needs_imports, &code, mod, imports); + code += classcode; const std::string directories = parser_.opts.one_file ? path_ : namer_.Directories(ns.components); diff --git a/tests/FromInclude.py b/tests/FromInclude.py deleted file mode 100644 index dbfcbffe7..000000000 --- a/tests/FromInclude.py +++ /dev/null @@ -1,5 +0,0 @@ -# automatically generated by the FlatBuffers compiler, do not modify - -# namespace: OtherNameSpace - -# NOTE FromInclude.py does not declare any structs or enums diff --git a/tests/MyGame/OtherNameSpace/FromInclude.py b/tests/MyGame/OtherNameSpace/FromInclude.py deleted file mode 100644 index dbfcbffe7..000000000 --- a/tests/MyGame/OtherNameSpace/FromInclude.py +++ /dev/null @@ -1,5 +0,0 @@ -# automatically generated by the FlatBuffers compiler, do not modify - -# namespace: OtherNameSpace - -# NOTE FromInclude.py does not declare any structs or enums diff --git a/tests/MyGame/OtherNameSpace/TableB.py b/tests/MyGame/OtherNameSpace/TableB.py deleted file mode 100644 index 1a3036938..000000000 --- a/tests/MyGame/OtherNameSpace/TableB.py +++ /dev/null @@ -1,5 +0,0 @@ -# automatically generated by the FlatBuffers compiler, do not modify - -# namespace: OtherNameSpace - -# NOTE TableB.py does not declare any structs or enums diff --git a/tests/MyGame/OtherNameSpace/Unused.py b/tests/MyGame/OtherNameSpace/Unused.py deleted file mode 100644 index bde02a747..000000000 --- a/tests/MyGame/OtherNameSpace/Unused.py +++ /dev/null @@ -1,5 +0,0 @@ -# automatically generated by the FlatBuffers compiler, do not modify - -# namespace: OtherNameSpace - -# NOTE Unused.py does not declare any structs or enums diff --git a/tests/MyGame/OtherNameSpace/__init__.py b/tests/MyGame/OtherNameSpace/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/TableA.py b/tests/TableA.py deleted file mode 100644 index ea081ffdc..000000000 --- a/tests/TableA.py +++ /dev/null @@ -1,5 +0,0 @@ -# automatically generated by the FlatBuffers compiler, do not modify - -# namespace: - -# NOTE TableA.py does not declare any structs or enums diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29bb..000000000