python: object generation prefix and suffix (#7565)

Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
inaryart 2022-10-29 08:37:27 +08:00 committed by GitHub
parent 051afd8825
commit 15f32c6907
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 6 deletions

View File

@ -1160,8 +1160,8 @@ class PythonGenerator : public BaseGenerator {
code += field_type + "()"; code += field_type + "()";
} }
code += ") is not None:"; code += ") is not None:";
code += GenIndents(3) + "self." + field_field + " = " + field_type + code += GenIndents(3) + "self." + field_field + " = " + namer_.ObjectType(field_type) +
"T.InitFromObj(" + struct_var + "." + field_method + "("; + ".InitFromObj(" + struct_var + "." + field_method + "(";
// A struct's accessor requires a struct buf instance. // A struct's accessor requires a struct buf instance.
if (struct_def.fixed && field.value.type.base_type == BASE_TYPE_STRUCT) { if (struct_def.fixed && field.value.type.base_type == BASE_TYPE_STRUCT) {
code += field_type + "()"; code += field_type + "()";
@ -1211,8 +1211,8 @@ class PythonGenerator : public BaseGenerator {
"(i) is None:"; "(i) is None:";
code += GenIndents(5) + "self." + field_field + ".append(None)"; code += GenIndents(5) + "self." + field_field + ".append(None)";
code += GenIndents(4) + "else:"; code += GenIndents(4) + "else:";
code += GenIndents(5) + one_instance + " = " + field_type + code += GenIndents(5) + one_instance + " = " + namer_.ObjectType(field_type) +
"T.InitFromObj(" + struct_var + "." + field_method + "(i))"; ".InitFromObj(" + struct_var + "." + field_method + "(i))";
code += code +=
GenIndents(5) + "self." + field_field + ".append(" + one_instance + ")"; GenIndents(5) + "self." + field_field + ".append(" + one_instance + ")";
} }
@ -1242,8 +1242,8 @@ class PythonGenerator : public BaseGenerator {
"(i) is None:"; "(i) is None:";
code += GenIndents(5) + "self." + field_field + ".append(None)"; code += GenIndents(5) + "self." + field_field + ".append(None)";
code += GenIndents(4) + "else:"; code += GenIndents(4) + "else:";
code += GenIndents(5) + one_instance + " = " + field_type + code += GenIndents(5) + one_instance + " = " + namer_.ObjectType(field_type) +
"T.InitFromObj(" + struct_var + "." + field_method + "(i))"; ".InitFromObj(" + struct_var + "." + field_method + "(i))";
code += code +=
GenIndents(5) + "self." + field_field + ".append(" + one_instance + ")"; GenIndents(5) + "self." + field_field + ".append(" + one_instance + ")";
} }