From 7c556b361a83e0cfff7b07efa6ebb3e4c8e0a1df Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Tue, 21 Jul 2020 10:51:18 +0200 Subject: [PATCH 1/2] Fix static type checking in grpclib client --- src/betterproto/grpc/grpclib_client.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/betterproto/grpc/grpclib_client.py b/src/betterproto/grpc/grpclib_client.py index 99ec8d778..6fa35b46f 100644 --- a/src/betterproto/grpc/grpclib_client.py +++ b/src/betterproto/grpc/grpclib_client.py @@ -13,17 +13,17 @@ Type, Union, ) -from .._types import ST, T +from betterproto._types import ST, T if TYPE_CHECKING: - from grpclib._typing import IProtoMessage from grpclib.client import Channel from grpclib.metadata import Deadline _Value = Union[str, bytes] _MetadataLike = Union[Mapping[str, _Value], Collection[Tuple[str, _Value]]] -_MessageSource = Union[Iterable["IProtoMessage"], AsyncIterable["IProtoMessage"]] +_MessageLike = Union[T, ST] +_MessageSource = Union[Iterable[ST], AsyncIterable[ST]] class ServiceStub(ABC): @@ -59,7 +59,7 @@ def __resolve_request_kwargs( async def _unary_unary( self, route: str, - request: "IProtoMessage", + request: _MessageLike, response_type: Type[T], *, timeout: Optional[float] = None, @@ -82,7 +82,7 @@ async def _unary_unary( async def _unary_stream( self, route: str, - request: "IProtoMessage", + request: _MessageLike, response_type: Type[T], *, timeout: Optional[float] = None, From ce2bea228dfbc12a9acccb6a2d097857f7163adc Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Sun, 26 Jul 2020 00:45:41 +0200 Subject: [PATCH 2/2] Fix python3.6 compatibility issue with dataclasses --- src/betterproto/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/betterproto/__init__.py b/src/betterproto/__init__.py index 008dec72d..f956a5cd2 100644 --- a/src/betterproto/__init__.py +++ b/src/betterproto/__init__.py @@ -664,7 +664,8 @@ def _cls_for(cls, field: dataclasses.Field, index: int = 0) -> Type: """Get the message class for a field from the type hints.""" field_cls = cls._type_hint(field.name) if hasattr(field_cls, "__args__") and index >= 0: - field_cls = field_cls.__args__[index] + if field_cls.__args__ is not None: + field_cls = field_cls.__args__[index] return field_cls def _get_field_default(self, field_name):