From beafc812ff3bda3938655e19e6ac56f49b67634a Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Thu, 30 Jul 2020 11:30:58 +0200 Subject: [PATCH] Fix static type checking for grpclib client (#124) * Fix static type checking in grpclib client * Fix python3.6 compatibility issue with dataclasses --- src/betterproto/__init__.py | 3 ++- src/betterproto/grpc/grpclib_client.py | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/betterproto/__init__.py b/src/betterproto/__init__.py index 008dec7..f956a5c 100644 --- a/src/betterproto/__init__.py +++ b/src/betterproto/__init__.py @@ -664,7 +664,8 @@ class Message(ABC): """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): diff --git a/src/betterproto/grpc/grpclib_client.py b/src/betterproto/grpc/grpclib_client.py index 99ec8d7..6fa35b4 100644 --- a/src/betterproto/grpc/grpclib_client.py +++ b/src/betterproto/grpc/grpclib_client.py @@ -13,17 +13,17 @@ from typing import ( 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 @@ class ServiceStub(ABC): async def _unary_unary( self, route: str, - request: "IProtoMessage", + request: _MessageLike, response_type: Type[T], *, timeout: Optional[float] = None, @@ -82,7 +82,7 @@ class ServiceStub(ABC): async def _unary_stream( self, route: str, - request: "IProtoMessage", + request: _MessageLike, response_type: Type[T], *, timeout: Optional[float] = None,