Remove references to the old MetadataType

pull/23045/head
Mariano Anaya 5 years ago
parent 6e83eb79f4
commit 36f79adaf9
  1. 7
      src/python/grpcio/grpc/experimental/aio/_base_call.py
  2. 13
      src/python/grpcio/grpc/experimental/aio/_base_channel.py
  3. 11
      src/python/grpcio/grpc/experimental/aio/_base_server.py
  4. 10
      src/python/grpcio/grpc/experimental/aio/_channel.py
  5. 33
      src/python/grpcio/grpc/experimental/aio/_interceptor.py
  6. 7
      src/python/grpcio_tests/tests_aio/unit/_common.py

@ -23,8 +23,9 @@ from typing import AsyncIterable, Awaitable, Generic, Optional, Union
import grpc
from ._typing import (DoneCallbackType, EOFType, MetadataType, RequestType,
from ._typing import (DoneCallbackType, EOFType, RequestType,
ResponseType)
from ._metadata import Metadata
__all__ = 'RpcContext', 'Call', 'UnaryUnaryCall', 'UnaryStreamCall'
@ -86,7 +87,7 @@ class Call(RpcContext, metaclass=ABCMeta):
"""The abstract base class of an RPC on the client-side."""
@abstractmethod
async def initial_metadata(self) -> MetadataType:
async def initial_metadata(self) -> Metadata:
"""Accesses the initial metadata sent by the server.
Returns:
@ -94,7 +95,7 @@ class Call(RpcContext, metaclass=ABCMeta):
"""
@abstractmethod
async def trailing_metadata(self) -> MetadataType:
async def trailing_metadata(self) -> Metadata:
"""Accesses the trailing metadata sent by the server.
Returns:

@ -19,10 +19,9 @@ from typing import Any, Optional
import grpc
from . import _base_call
from ._typing import (DeserializingFunction, MetadataType, RequestIterableType,
from ._typing import (DeserializingFunction, RequestIterableType,
SerializingFunction)
_IMMUTABLE_EMPTY_TUPLE = tuple()
from ._metadata import Metadata
class UnaryUnaryMultiCallable(abc.ABC):
@ -33,7 +32,7 @@ class UnaryUnaryMultiCallable(abc.ABC):
request: Any,
*,
timeout: Optional[float] = None,
metadata: Optional[MetadataType] = _IMMUTABLE_EMPTY_TUPLE,
metadata: Optional[Metadata] = None,
credentials: Optional[grpc.CallCredentials] = None,
wait_for_ready: Optional[bool] = None,
compression: Optional[grpc.Compression] = None
@ -71,7 +70,7 @@ class UnaryStreamMultiCallable(abc.ABC):
request: Any,
*,
timeout: Optional[float] = None,
metadata: Optional[MetadataType] = _IMMUTABLE_EMPTY_TUPLE,
metadata: Optional[Metadata] = None,
credentials: Optional[grpc.CallCredentials] = None,
wait_for_ready: Optional[bool] = None,
compression: Optional[grpc.Compression] = None
@ -108,7 +107,7 @@ class StreamUnaryMultiCallable(abc.ABC):
def __call__(self,
request_iterator: Optional[RequestIterableType] = None,
timeout: Optional[float] = None,
metadata: Optional[MetadataType] = _IMMUTABLE_EMPTY_TUPLE,
metadata: Optional[Metadata] = None,
credentials: Optional[grpc.CallCredentials] = None,
wait_for_ready: Optional[bool] = None,
compression: Optional[grpc.Compression] = None
@ -146,7 +145,7 @@ class StreamStreamMultiCallable(abc.ABC):
def __call__(self,
request_iterator: Optional[RequestIterableType] = None,
timeout: Optional[float] = None,
metadata: Optional[MetadataType] = _IMMUTABLE_EMPTY_TUPLE,
metadata: Optional[Metadata] = None,
credentials: Optional[grpc.CallCredentials] = None,
wait_for_ready: Optional[bool] = None,
compression: Optional[grpc.Compression] = None

@ -18,7 +18,8 @@ from typing import Generic, Optional, Sequence
import grpc
from ._typing import MetadataType, RequestType, ResponseType
from ._typing import RequestType, ResponseType
from ._metadata import Metadata
class Server(abc.ABC):
@ -158,7 +159,7 @@ class ServicerContext(Generic[RequestType, ResponseType], abc.ABC):
@abc.abstractmethod
async def send_initial_metadata(self,
initial_metadata: MetadataType) -> None:
initial_metadata: Metadata) -> None:
"""Sends the initial metadata value to the client.
This method need not be called by implementations if they have no
@ -170,7 +171,7 @@ class ServicerContext(Generic[RequestType, ResponseType], abc.ABC):
@abc.abstractmethod
async def abort(self, code: grpc.StatusCode, details: str,
trailing_metadata: MetadataType) -> None:
trailing_metadata: Metadata) -> None:
"""Raises an exception to terminate the RPC with a non-OK status.
The code and details passed as arguments will supercede any existing
@ -191,7 +192,7 @@ class ServicerContext(Generic[RequestType, ResponseType], abc.ABC):
@abc.abstractmethod
async def set_trailing_metadata(self,
trailing_metadata: MetadataType) -> None:
trailing_metadata: Metadata) -> None:
"""Sends the trailing metadata for the RPC.
This method need not be called by implementations if they have no
@ -202,7 +203,7 @@ class ServicerContext(Generic[RequestType, ResponseType], abc.ABC):
"""
@abc.abstractmethod
def invocation_metadata(self) -> Optional[MetadataType]:
def invocation_metadata(self) -> Optional[Metadata]:
"""Accesses the metadata from the sent by the client.
Returns:

@ -30,7 +30,7 @@ from ._interceptor import (
UnaryUnaryClientInterceptor, UnaryStreamClientInterceptor,
StreamUnaryClientInterceptor, StreamStreamClientInterceptor)
from ._metadata import Metadata
from ._typing import (ChannelArgumentType, DeserializingFunction, MetadataType,
from ._typing import (ChannelArgumentType, DeserializingFunction,
SerializingFunction, RequestIterableType)
from ._utils import _timeout_to_deadline
@ -109,7 +109,7 @@ class UnaryUnaryMultiCallable(_BaseMultiCallable,
request: Any,
*,
timeout: Optional[float] = None,
metadata: Optional[MetadataType] = None,
metadata: Optional[Metadata] = None,
credentials: Optional[grpc.CallCredentials] = None,
wait_for_ready: Optional[bool] = None,
compression: Optional[grpc.Compression] = None
@ -139,7 +139,7 @@ class UnaryStreamMultiCallable(_BaseMultiCallable,
request: Any,
*,
timeout: Optional[float] = None,
metadata: Optional[MetadataType] = None,
metadata: Optional[Metadata] = None,
credentials: Optional[grpc.CallCredentials] = None,
wait_for_ready: Optional[bool] = None,
compression: Optional[grpc.Compression] = None
@ -169,7 +169,7 @@ class StreamUnaryMultiCallable(_BaseMultiCallable,
def __call__(self,
request_iterator: Optional[RequestIterableType] = None,
timeout: Optional[float] = None,
metadata: Optional[MetadataType] = None,
metadata: Optional[Metadata] = None,
credentials: Optional[grpc.CallCredentials] = None,
wait_for_ready: Optional[bool] = None,
compression: Optional[grpc.Compression] = None
@ -199,7 +199,7 @@ class StreamStreamMultiCallable(_BaseMultiCallable,
def __call__(self,
request_iterator: Optional[RequestIterableType] = None,
timeout: Optional[float] = None,
metadata: Optional[MetadataType] = None,
metadata: Optional[Metadata] = None,
credentials: Optional[grpc.CallCredentials] = None,
wait_for_ready: Optional[bool] = None,
compression: Optional[grpc.Compression] = None

@ -27,8 +27,9 @@ from ._call import _RPC_ALREADY_FINISHED_DETAILS, _RPC_HALF_CLOSED_DETAILS
from ._call import _API_STYLE_ERROR
from ._utils import _timeout_to_deadline
from ._typing import (RequestType, SerializingFunction, DeserializingFunction,
MetadataType, ResponseType, DoneCallbackType,
ResponseType, DoneCallbackType,
RequestIterableType, ResponseIterableType)
from ._metadata import Metadata
_LOCAL_CANCELLATION_DETAILS = 'Locally cancelled by application!'
@ -82,7 +83,7 @@ class ClientCallDetails(
method: str
timeout: Optional[float]
metadata: Optional[MetadataType]
metadata: Optional[Metadata]
credentials: Optional[grpc.CallCredentials]
wait_for_ready: Optional[bool]
@ -370,7 +371,7 @@ class InterceptedCall:
def time_remaining(self) -> Optional[float]:
raise NotImplementedError()
async def initial_metadata(self) -> Optional[MetadataType]:
async def initial_metadata(self) -> Optional[Metadata]:
try:
call = await self._interceptors_task
except AioRpcError as err:
@ -380,7 +381,7 @@ class InterceptedCall:
return await call.initial_metadata()
async def trailing_metadata(self) -> Optional[MetadataType]:
async def trailing_metadata(self) -> Optional[Metadata]:
try:
call = await self._interceptors_task
except AioRpcError as err:
@ -556,7 +557,7 @@ class InterceptedUnaryUnaryCall(_InterceptedUnaryResponseMixin, InterceptedCall,
# pylint: disable=too-many-arguments
def __init__(self, interceptors: Sequence[UnaryUnaryClientInterceptor],
request: RequestType, timeout: Optional[float],
metadata: MetadataType,
metadata: Metadata,
credentials: Optional[grpc.CallCredentials],
wait_for_ready: Optional[bool], channel: cygrpc.AioChannel,
method: bytes, request_serializer: SerializingFunction,
@ -573,7 +574,7 @@ class InterceptedUnaryUnaryCall(_InterceptedUnaryResponseMixin, InterceptedCall,
# pylint: disable=too-many-arguments
async def _invoke(self, interceptors: Sequence[UnaryUnaryClientInterceptor],
method: bytes, timeout: Optional[float],
metadata: Optional[MetadataType],
metadata: Optional[Metadata],
credentials: Optional[grpc.CallCredentials],
wait_for_ready: Optional[bool], request: RequestType,
request_serializer: SerializingFunction,
@ -628,7 +629,7 @@ class InterceptedUnaryStreamCall(_InterceptedStreamResponseMixin,
# pylint: disable=too-many-arguments
def __init__(self, interceptors: Sequence[UnaryStreamClientInterceptor],
request: RequestType, timeout: Optional[float],
metadata: MetadataType,
metadata: Metadata,
credentials: Optional[grpc.CallCredentials],
wait_for_ready: Optional[bool], channel: cygrpc.AioChannel,
method: bytes, request_serializer: SerializingFunction,
@ -647,7 +648,7 @@ class InterceptedUnaryStreamCall(_InterceptedStreamResponseMixin,
# pylint: disable=too-many-arguments
async def _invoke(self, interceptors: Sequence[UnaryUnaryClientInterceptor],
method: bytes, timeout: Optional[float],
metadata: Optional[MetadataType],
metadata: Optional[Metadata],
credentials: Optional[grpc.CallCredentials],
wait_for_ready: Optional[bool], request: RequestType,
request_serializer: SerializingFunction,
@ -712,7 +713,7 @@ class InterceptedStreamUnaryCall(_InterceptedUnaryResponseMixin,
# pylint: disable=too-many-arguments
def __init__(self, interceptors: Sequence[StreamUnaryClientInterceptor],
request_iterator: Optional[RequestIterableType],
timeout: Optional[float], metadata: MetadataType,
timeout: Optional[float], metadata: Metadata,
credentials: Optional[grpc.CallCredentials],
wait_for_ready: Optional[bool], channel: cygrpc.AioChannel,
method: bytes, request_serializer: SerializingFunction,
@ -731,7 +732,7 @@ class InterceptedStreamUnaryCall(_InterceptedUnaryResponseMixin,
async def _invoke(
self, interceptors: Sequence[StreamUnaryClientInterceptor],
method: bytes, timeout: Optional[float],
metadata: Optional[MetadataType],
metadata: Optional[Metadata],
credentials: Optional[grpc.CallCredentials],
wait_for_ready: Optional[bool],
request_iterator: RequestIterableType,
@ -783,7 +784,7 @@ class InterceptedStreamStreamCall(_InterceptedStreamResponseMixin,
# pylint: disable=too-many-arguments
def __init__(self, interceptors: Sequence[StreamStreamClientInterceptor],
request_iterator: Optional[RequestIterableType],
timeout: Optional[float], metadata: MetadataType,
timeout: Optional[float], metadata: Metadata,
credentials: Optional[grpc.CallCredentials],
wait_for_ready: Optional[bool], channel: cygrpc.AioChannel,
method: bytes, request_serializer: SerializingFunction,
@ -804,7 +805,7 @@ class InterceptedStreamStreamCall(_InterceptedStreamResponseMixin,
async def _invoke(
self, interceptors: Sequence[StreamStreamClientInterceptor],
method: bytes, timeout: Optional[float],
metadata: Optional[MetadataType],
metadata: Optional[Metadata],
credentials: Optional[grpc.CallCredentials],
wait_for_ready: Optional[bool],
request_iterator: RequestIterableType,
@ -876,10 +877,10 @@ class UnaryUnaryCallResponse(_base_call.UnaryUnaryCall):
def time_remaining(self) -> Optional[float]:
raise NotImplementedError()
async def initial_metadata(self) -> Optional[MetadataType]:
async def initial_metadata(self) -> Optional[Metadata]:
return None
async def trailing_metadata(self) -> Optional[MetadataType]:
async def trailing_metadata(self) -> Optional[Metadata]:
return None
async def code(self) -> grpc.StatusCode:
@ -928,10 +929,10 @@ class _StreamCallResponseIterator:
def time_remaining(self) -> Optional[float]:
return self._call.time_remaining()
async def initial_metadata(self) -> Optional[MetadataType]:
async def initial_metadata(self) -> Optional[Metadata]:
return await self._call.initial_metadata()
async def trailing_metadata(self) -> Optional[MetadataType]:
async def trailing_metadata(self) -> Optional[Metadata]:
return await self._call.trailing_metadata()
async def code(self) -> grpc.StatusCode:

@ -16,17 +16,18 @@ import asyncio
import grpc
from typing import AsyncIterable
from grpc.experimental import aio
from grpc.experimental.aio._typing import MetadataType, MetadatumType, MetadataKey, MetadataValue
from grpc.experimental.aio._typing import MetadatumType, MetadataKey, MetadataValue
from grpc.experimental.aio._metadata import Metadata
from tests.unit.framework.common import test_constants
def seen_metadata(expected: MetadataType, actual: MetadataType):
def seen_metadata(expected: Metadata, actual: Metadata):
return not bool(set(tuple(expected)) - set(tuple(actual)))
def seen_metadatum(expected_key: MetadataKey, expected_value: MetadataValue,
actual: MetadataType) -> bool:
actual: Metadata) -> bool:
obtained = actual[expected_key]
return obtained == expected_value

Loading…
Cancel
Save