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

[python-runtime] Add MethodDescriptor.CopyToProto() #8327

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions python/google/protobuf/descriptor.py
Expand Up @@ -912,6 +912,24 @@ def __init__(self, name, full_name, index, containing_service,
self.containing_service = containing_service
self.input_type = input_type
self.output_type = output_type

def CopyToProto(self, proto):
"""Copies this to a descriptor_pb2.MethodDescriptorProto.

Args:
proto (descriptor_pb2.MethodDescriptorProto): An empty descriptor proto.

Raises:
Error: If self couldn't be serialized, due to too few constructor
arguments.
"""
if self.containing_service is not None:
from google.protobuf import descriptor_pb2
service_proto = descriptor_pb2.ServiceDescriptorProto()
self.containing_service.CopyToProto(service_proto)
proto.CopyFrom(service_proto.method[self.index])
else:
raise Error('Descriptor does not contain a service.')


class FileDescriptor(DescriptorBase):
Expand Down
4 changes: 0 additions & 4 deletions python/google/protobuf/internal/descriptor_test.py
Expand Up @@ -907,10 +907,6 @@ def testCopyToProto_ServiceDescriptor(self):
descriptor_pb2.ServiceDescriptorProto,
TEST_SERVICE_ASCII)

@unittest.skipIf(
api_implementation.Type() == 'python',
'It is not implemented in python.')
# TODO(jieluo): Add support for pure python or remove in c extension.
def testCopyToProto_MethodDescriptor(self):
expected_ascii = """
name: 'Foo'
Expand Down