@@ -137,6 +137,8 @@ def wrap_method(
137137 default_timeout = None ,
138138 default_compression = None ,
139139 client_info = client_info .DEFAULT_CLIENT_INFO ,
140+ * ,
141+ with_call = False ,
140142):
141143 """Wrap an RPC method with common behavior.
142144
@@ -216,13 +218,24 @@ def get_topic(name, timeout=None):
216218 passed as gRPC metadata to the method. If unspecified, then
217219 a sane default will be used. If ``None``, then no user agent
218220 metadata will be provided to the RPC method.
221+ with_call (bool): If True, wrapped grpc.UnaryUnaryMulticallables will
222+ return a tuple of (response, grpc.Call) instead of just the response.
223+ This is useful for extracting trailing metadata from unary calls.
224+ Defaults to False.
219225
220226 Returns:
221227 Callable: A new callable that takes optional ``retry``, ``timeout``,
222228 and ``compression``
223229 arguments and applies the common error mapping, retry, timeout, compression,
224230 and metadata behavior to the low-level RPC method.
225231 """
232+ if with_call :
233+ try :
234+ func = func .with_call
235+ except AttributeError as exc :
236+ raise ValueError (
237+ "with_call=True is only supported for unary calls."
238+ ) from exc
226239 func = grpc_helpers .wrap_errors (func )
227240 if client_info is not None :
228241 user_agent_metadata = [client_info .to_grpc_metadata ()]
0 commit comments