Skip to content

Commit

Permalink
Remove deprecated GetPrototype usages in google/protobuf/ to git rid …
Browse files Browse the repository at this point in the history
…of the

warinings

PiperOrigin-RevId: 654836977
  • Loading branch information
anandolee authored and copybara-github committed Jul 22, 2024
1 parent a1c53e4 commit c37dd57
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion python/google/protobuf/internal/descriptor_pool_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def _CheckDefaultValues(msg):
unittest_import_pb2.DESCRIPTOR.serialized_pb))
pool.Add(descriptor_pb2.FileDescriptorProto.FromString(
unittest_pb2.DESCRIPTOR.serialized_pb))
message_class = message_factory.MessageFactory(pool).GetPrototype(
message_class = message_factory.GetMessageClass(
pool.FindMessageTypeByName(
unittest_pb2.TestAllTypes.DESCRIPTOR.full_name))
_CheckDefaultValues(message_class())
Expand Down
2 changes: 1 addition & 1 deletion python/google/protobuf/internal/message_factory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _ExerciseDynamicClass(self, cls):
result = cls.FromString(reserialized)
self.assertEqual(msg, result)

def testGetPrototype(self):
def testGetMessageClass(self):
db = descriptor_database.DescriptorDatabase()
pool = descriptor_pool.DescriptorPool(db)
db.Add(self.factory_test1_fd)
Expand Down
9 changes: 6 additions & 3 deletions python/google/protobuf/internal/python_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class GeneratedProtocolMessageType(type):
mydescriptor = Descriptor(.....)
factory = symbol_database.Default()
factory.pool.AddDescriptor(mydescriptor)
MyProtoClass = factory.GetPrototype(mydescriptor)
MyProtoClass = message_factory.GetMessageClass(mydescriptor)
myproto_instance = MyProtoClass()
myproto.foo_field = 23
...
Expand Down Expand Up @@ -120,7 +120,7 @@ def __new__(cls, name, bases, dictionary):
# to achieve similar results.
#
# This most commonly happens in `text_format.py` when using descriptors from
# a custom pool; it calls symbol_database.Global().getPrototype() on a
# a custom pool; it calls message_factory.GetMessageClass() on a
# descriptor which already has an existing concrete class.
new_class = getattr(descriptor, '_concrete_class', None)
if new_class:
Expand Down Expand Up @@ -988,7 +988,10 @@ def _InternalUnpackAny(msg):
if descriptor is None:
return None

message_class = factory.GetPrototype(descriptor)
# Unable to import message_factory at top becaue of circular import.
# pylint: disable=g-import-not-at-top
from google.protobuf import message_factory
message_class = message_factory.GetMessageClass(descriptor)
message = message_class()

message.ParseFromString(msg.value)
Expand Down
5 changes: 0 additions & 5 deletions python/google/protobuf/internal/symbol_database_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ def _Database(self):
db.RegisterServiceDescriptor(unittest_pb2._TESTSERVICE)
return db

def testGetPrototype(self):
instance = self._Database().GetPrototype(
unittest_pb2.TestAllTypes.DESCRIPTOR)
self.assertTrue(instance is unittest_pb2.TestAllTypes)

def testGetMessages(self):
messages = self._Database().GetMessages(
['google/protobuf/unittest.proto'])
Expand Down
2 changes: 1 addition & 1 deletion python/google/protobuf/pyext/cpp_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GeneratedProtocolMessageType(_message.MessageMeta):
mydescriptor = Descriptor(.....)
factory = symbol_database.Default()
factory.pool.AddDescriptor(mydescriptor)
MyProtoClass = factory.GetPrototype(mydescriptor)
MyProtoClass = message_factory.GetMessageClass(mydescriptor)
myproto_instance = MyProtoClass()
myproto.foo_field = 23
...
Expand Down

0 comments on commit c37dd57

Please sign in to comment.