Skip to content

Commit e4baf96

Browse files
authored
Merge pull request #14240 from vthib/backport-cython-fix
Backport fix python code generation compatibility with Cython on 24.x
2 parents b2b7a51 + fe87c90 commit e4baf96

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/google/protobuf/compiler/python/generator.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,10 +1194,18 @@ void PrintDescriptorOptionsFixingCode(absl::string_view descriptor,
11941194
io::Printer* printer) {
11951195
// Reset the _options to None thus DescriptorBase.GetOptions() can
11961196
// parse _options again after extensions are registered.
1197+
size_t dot_pos = descriptor.find('.');
1198+
std::string descriptor_name;
1199+
if (dot_pos == std::string::npos) {
1200+
descriptor_name = absl::StrCat("_globals['", descriptor, "']");
1201+
} else {
1202+
descriptor_name = absl::StrCat("_globals['", descriptor.substr(0, dot_pos),
1203+
"']", descriptor.substr(dot_pos));
1204+
}
11971205
printer->Print(
1198-
"$descriptor$._options = None\n"
1199-
"$descriptor$._serialized_options = $serialized_value$\n",
1200-
"descriptor", descriptor, "serialized_value", options);
1206+
"$descriptor_name$._options = None\n"
1207+
"$descriptor_name$._serialized_options = $serialized_value$\n",
1208+
"descriptor_name", descriptor_name, "serialized_value", options);
12011209
}
12021210
} // namespace
12031211

0 commit comments

Comments
 (0)