Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport fix python code generation compatibility with Cython on 24.x #14240

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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