From 2967c521a60241c35fb822c1661618493f824dda Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Wed, 17 Jul 2024 10:29:40 -0700 Subject: [PATCH] -Remove service.py usages in builder -Raise warnings for deprecated google/protobuf/service.py APIs. service.py APIs are marked as deprecated since 2010. These APIs will be removed in Jan 2025 PiperOrigin-RevId: 653280370 --- python/google/protobuf/internal/builder.py | 3 +-- python/google/protobuf/service.py | 8 ++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/python/google/protobuf/internal/builder.py b/python/google/protobuf/internal/builder.py index c22d994778..4c0f2873d8 100644 --- a/python/google/protobuf/internal/builder.py +++ b/python/google/protobuf/internal/builder.py @@ -105,12 +105,11 @@ def BuildServices(file_des, module_name, module): module: Generated _pb2 module """ # pylint: disable=g-import-not-at-top - from google.protobuf import service as _service from google.protobuf import service_reflection # pylint: enable=g-import-not-at-top for (name, service) in file_des.services_by_name.items(): module[name] = service_reflection.GeneratedServiceType( - name, (_service.Service,), + name, (), dict(DESCRIPTOR=service, __module__=module_name)) stub_name = name + '_Stub' module[stub_name] = service_reflection.GeneratedServiceStubType( diff --git a/python/google/protobuf/service.py b/python/google/protobuf/service.py index d3e192009f..38b8217919 100644 --- a/python/google/protobuf/service.py +++ b/python/google/protobuf/service.py @@ -19,6 +19,14 @@ and can avoid unnecessary layers of indirection. __author__ = 'petar@google.com (Petar Petrov)' +import warnings + +warnings.warn( + 'google.protobuf.service module is deprecated. RPC implementations ' + 'should provide code generator plugins which generate code specific to ' + 'the RPC implementation. service.py will be removed in Jan 2025', + stacklevel=2, +) class RpcException(Exception): """Exception raised on failed blocking RPC method call."""