Optionally generate Python type annotations (#7858)

* optionally generate type prefixes and suffixes for python code

* fix codegen error when qualified name is empty

* WIP: Python typing

* more progress towards python typing

* Further iterate on Python generated code typing

* clang-format

* Regenerate code

* add documentation for Python type annotations option

* generate code with Python type annotations

* handle forward references

* clang-format
This commit is contained in:
Max Burke
2023-04-28 09:38:29 -07:00
committed by GitHub
parent 6eae49a79a
commit a397dd7e8c
35 changed files with 1295 additions and 979 deletions

View File

@@ -252,6 +252,8 @@ const static FlatCOption flatc_options[] = {
"Currently this is required to generate private types in Rust" },
{ "", "python-no-type-prefix-suffix", "",
"Skip emission of Python functions that are prefixed with typenames" },
{ "", "python-typing", "",
"Generate Python type annotations" },
{ "", "file-names-only", "",
"Print out generated file names without writing to the files"},
};
@@ -652,9 +654,11 @@ FlatCOptions FlatCompiler::ParseFromCommandLineArguments(int argc,
opts.ts_no_import_ext = true;
} else if (arg == "--no-leak-private-annotation") {
opts.no_leak_private_annotations = true;
} else if (arg == "--python-no-type-prefix-suffix") {
} else if (arg == "--python-no-type-prefix-suffix") {
opts.python_no_type_prefix_suffix = true;
} else if (arg == "--annotate-sparse-vectors") {
} else if (arg == "--python-typing") {
opts.python_typing = true;
} else if (arg == "--annotate-sparse-vectors") {
options.annotate_include_vector_contents = false;
} else if (arg == "--annotate") {
if (++argi >= argc) Error("missing path following: " + arg, true);