Skip to content

[Python] Inconsistent python generation of union creator types #8843

@jbland64

Description

@jbland64

Naming convention for defining the union creator function

    const auto enum_fn = namer_.Function(enum_def);
    code += "\n";
    code += "def " + enum_fn + "Creator(unionType, table):";

https://github.com/google/flatbuffers/blob/master/src/idl_gen_python.cpp#L2594

Differs to the naming convention for calling it

    auto union_type = namer_.Type(enum_def);

    if (parser_.opts.include_dependence_headers) {
      union_type = namer_.NamespacedType(enum_def) + "." + union_type;
    }
    code += GenIndents(2) + "self." + field_field + " = " + union_type +
            "Creator(" + "self." + field_field + "Type, " + struct_var + "." +
            field_method + "())";
  }

https://github.com/google/flatbuffers/blob/master/src/idl_gen_python.cpp#L2029

I solved this locally by changing:

auto union_type = namer_.Type(enum_def);
to:
auto union_type = namer_.Function(enum_def);

I have not accounted for

    if (parser_.opts.include_dependence_headers) {
      union_type = namer_.NamespacedType(enum_def) + "." + union_type;
    }

This may need an additional method

  std::string NamespacedFunction(const Definition& def) const {
    return NamespacedString(def.defined_namespace, Function(def.name));
  }

but i have not tested this the name namespace functionality

Metadata

Metadata

Assignees

Labels

pr-requestedA Pull Request is requested to move the issue forward.python

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions