Skip to content

Commit

Permalink
Merge pull request #14240 from vthib/backport-cython-fix
Browse files Browse the repository at this point in the history
Backport fix python code generation compatibility with Cython on 24.x
  • Loading branch information
fowles authored Sep 28, 2023
2 parents b2b7a51 + fe87c90 commit e4baf96
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 e4baf96

Please sign in to comment.