You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
flatc --python creates an empty __init__.py in every folder of the
namespace path. If one of those folders already has a hand-written __init__.py with code in it, flatc replaces it with an empty file without warning.
Why
I wanted the generated files to live under my apps ipc folder which deals with the websocket server and the flatbuffer stuff
Repro
Project already has these real files:
src/myapp/__init__.py # e.g. `def main(): ...`
src/myapp/ipc/__init__.py # e.g. re-exports
Now src/myapp/__init__.py and src/myapp/ipc/__init__.py are empty.
I found it happened through basedpyright lsp: ImportError: cannot import name 'main' from 'myapp'.
Expected
flatc should not destroy source files it did not generate. Any of:
don't touch an __init__.py in a folder that already exists
never overwrite a non-empty __init__.py
only write __init__.py for the innermost namespace folder
add a flag like --python-no-init
Notes
--gen-onefile skips the __init__.py chain but doesn't emit
cross-schema imports, so it breaks for schemas that use include. Not a
workaround.
--ts is fine — it writes into a fresh tree and doesn't clobber
hand-written files.
flatc --help (25.12.19) has no flag to control __init__.py output.
Workarounds
Generate into a temp dir, move only the leaf namespace folder into place.
Give the generated code its own top-level package, with a namespace
prefix no hand-written module shares.
Activity
fix(python): preserve existing __init__.py files during code generati…