Skip to content

Commit

Permalink
fix python code generation compatibility with Cython
Browse files Browse the repository at this point in the history
raised by #13593

PiperOrigin-RevId: 561077681
  • Loading branch information
anandolee authored and vthib committed Sep 28, 2023
1 parent b2b7a51 commit fe87c90
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/google/protobuf/compiler/python/generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1194,10 +1194,18 @@ void PrintDescriptorOptionsFixingCode(absl::string_view descriptor,
io::Printer* printer) {
// Reset the _options to None thus DescriptorBase.GetOptions() can
// parse _options again after extensions are registered.
size_t dot_pos = descriptor.find('.');
std::string descriptor_name;
if (dot_pos == std::string::npos) {
descriptor_name = absl::StrCat("_globals['", descriptor, "']");
} else {
descriptor_name = absl::StrCat("_globals['", descriptor.substr(0, dot_pos),
"']", descriptor.substr(dot_pos));
}
printer->Print(
"$descriptor$._options = None\n"
"$descriptor$._serialized_options = $serialized_value$\n",
"descriptor", descriptor, "serialized_value", options);
"$descriptor_name$._options = None\n"
"$descriptor_name$._serialized_options = $serialized_value$\n",
"descriptor_name", descriptor_name, "serialized_value", options);
}
} // namespace

Expand Down

0 comments on commit fe87c90

Please sign in to comment.