[Aio] Correct the typing of input Metadata (#27768)

pull/27767/head
Lidi Zheng 4 years ago committed by GitHub
parent 790ce5c97f
commit 2bc96189b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      src/python/grpcio/grpc/aio/_base_channel.py
  2. 8
      src/python/grpcio/grpc/aio/_base_server.py
  3. 2
      src/python/grpcio/grpc/aio/_typing.py

@ -19,8 +19,8 @@ from typing import Any, Optional
import grpc import grpc
from . import _base_call from . import _base_call
from ._metadata import Metadata
from ._typing import DeserializingFunction from ._typing import DeserializingFunction
from ._typing import MetadataType
from ._typing import RequestIterableType from ._typing import RequestIterableType
from ._typing import SerializingFunction from ._typing import SerializingFunction
@ -34,7 +34,7 @@ class UnaryUnaryMultiCallable(abc.ABC):
request: Any, request: Any,
*, *,
timeout: Optional[float] = None, timeout: Optional[float] = None,
metadata: Optional[Metadata] = None, metadata: Optional[MetadataType] = None,
credentials: Optional[grpc.CallCredentials] = None, credentials: Optional[grpc.CallCredentials] = None,
wait_for_ready: Optional[bool] = None, wait_for_ready: Optional[bool] = None,
compression: Optional[grpc.Compression] = None compression: Optional[grpc.Compression] = None
@ -73,7 +73,7 @@ class UnaryStreamMultiCallable(abc.ABC):
request: Any, request: Any,
*, *,
timeout: Optional[float] = None, timeout: Optional[float] = None,
metadata: Optional[Metadata] = None, metadata: Optional[MetadataType] = None,
credentials: Optional[grpc.CallCredentials] = None, credentials: Optional[grpc.CallCredentials] = None,
wait_for_ready: Optional[bool] = None, wait_for_ready: Optional[bool] = None,
compression: Optional[grpc.Compression] = None compression: Optional[grpc.Compression] = None
@ -111,7 +111,7 @@ class StreamUnaryMultiCallable(abc.ABC):
self, self,
request_iterator: Optional[RequestIterableType] = None, request_iterator: Optional[RequestIterableType] = None,
timeout: Optional[float] = None, timeout: Optional[float] = None,
metadata: Optional[Metadata] = None, metadata: Optional[MetadataType] = None,
credentials: Optional[grpc.CallCredentials] = None, credentials: Optional[grpc.CallCredentials] = None,
wait_for_ready: Optional[bool] = None, wait_for_ready: Optional[bool] = None,
compression: Optional[grpc.Compression] = None compression: Optional[grpc.Compression] = None
@ -150,7 +150,7 @@ class StreamStreamMultiCallable(abc.ABC):
self, self,
request_iterator: Optional[RequestIterableType] = None, request_iterator: Optional[RequestIterableType] = None,
timeout: Optional[float] = None, timeout: Optional[float] = None,
metadata: Optional[Metadata] = None, metadata: Optional[MetadataType] = None,
credentials: Optional[grpc.CallCredentials] = None, credentials: Optional[grpc.CallCredentials] = None,
wait_for_ready: Optional[bool] = None, wait_for_ready: Optional[bool] = None,
compression: Optional[grpc.Compression] = None compression: Optional[grpc.Compression] = None

@ -19,6 +19,7 @@ from typing import Generic, Iterable, Mapping, Optional, Sequence
import grpc import grpc
from ._metadata import Metadata from ._metadata import Metadata
from ._typing import MetadataType
from ._typing import RequestType from ._typing import RequestType
from ._typing import ResponseType from ._typing import ResponseType
@ -159,7 +160,8 @@ class ServicerContext(Generic[RequestType, ResponseType], abc.ABC):
""" """
@abc.abstractmethod @abc.abstractmethod
async def send_initial_metadata(self, initial_metadata: Metadata) -> None: async def send_initial_metadata(self,
initial_metadata: MetadataType) -> None:
"""Sends the initial metadata value to the client. """Sends the initial metadata value to the client.
This method need not be called by implementations if they have no This method need not be called by implementations if they have no
@ -174,7 +176,7 @@ class ServicerContext(Generic[RequestType, ResponseType], abc.ABC):
self, self,
code: grpc.StatusCode, code: grpc.StatusCode,
details: str = '', details: str = '',
trailing_metadata: Metadata = tuple()) -> None: trailing_metadata: MetadataType = tuple()) -> None:
"""Raises an exception to terminate the RPC with a non-OK status. """Raises an exception to terminate the RPC with a non-OK status.
The code and details passed as arguments will supercede any existing The code and details passed as arguments will supercede any existing
@ -194,7 +196,7 @@ class ServicerContext(Generic[RequestType, ResponseType], abc.ABC):
""" """
@abc.abstractmethod @abc.abstractmethod
def set_trailing_metadata(self, trailing_metadata: Metadata) -> None: def set_trailing_metadata(self, trailing_metadata: MetadataType) -> None:
"""Sends the trailing metadata for the RPC. """Sends the trailing metadata for the RPC.
This method need not be called by implementations if they have no This method need not be called by implementations if they have no

@ -27,7 +27,7 @@ ResponseType = TypeVar('ResponseType')
SerializingFunction = Callable[[Any], bytes] SerializingFunction = Callable[[Any], bytes]
DeserializingFunction = Callable[[bytes], Any] DeserializingFunction = Callable[[bytes], Any]
MetadatumType = Tuple[MetadataKey, MetadataValue] MetadatumType = Tuple[MetadataKey, MetadataValue]
MetadataType = Metadata MetadataType = Union[Metadata, Sequence[MetadatumType]]
ChannelArgumentType = Sequence[Tuple[str, Any]] ChannelArgumentType = Sequence[Tuple[str, Any]]
EOFType = type(EOF) EOFType = type(EOF)
DoneCallbackType = Callable[[Any], None] DoneCallbackType = Callable[[Any], None]

Loading…
Cancel
Save