Skip to content

Commit 38ca2d3

Browse files
habermancopybara-github
authored andcommitted
Fixed mypy errors by setting __slots__ to empty in .pyi files.
The `__slots__` are redundant, since they duplicate the members we already have. Also, they cause problems with mypy: #21691 We have to leave an empty `__slots__ = ()` in place, as opposed to removing it entirely, because that's the only way to ensure that pytype will continue to error out if an unknown member is read or written. PiperOrigin-RevId: 795107868
1 parent d2d2115 commit 38ca2d3

File tree

1 file changed

+1
-15
lines changed

1 file changed

+1
-15
lines changed

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -444,21 +444,7 @@ void PyiGenerator::PrintMessage(const Descriptor& message_descriptor,
444444
Annotate("class_name", &message_descriptor);
445445
printer_->Indent();
446446

447-
// Prints slots
448-
printer_->Print("__slots__ = (");
449-
int items_printed = 0;
450-
for (int i = 0; i < message_descriptor.field_count(); ++i) {
451-
const FieldDescriptor* field_des = message_descriptor.field(i);
452-
if (IsPythonKeyword(field_des->name())) {
453-
continue;
454-
}
455-
if (items_printed > 0) {
456-
printer_->Print(", ");
457-
}
458-
++items_printed;
459-
printer_->Print("\"$field_name$\"", "field_name", field_des->name());
460-
}
461-
printer_->Print(items_printed == 1 ? ",)\n" : ")\n");
447+
printer_->Print("__slots__ = ()\n");
462448

463449
// Prints Extensions for extendable messages
464450
if (message_descriptor.extension_range_count() > 0) {

0 commit comments

Comments
 (0)