Skip to content

Commit beafc81

Browse files
authored
Fix static type checking for grpclib client (danielgtaylor#124)
* Fix static type checking in grpclib client * Fix python3.6 compatibility issue with dataclasses
1 parent 3d8c0cb commit beafc81

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/betterproto/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,8 @@ def _cls_for(cls, field: dataclasses.Field, index: int = 0) -> Type:
664664
"""Get the message class for a field from the type hints."""
665665
field_cls = cls._type_hint(field.name)
666666
if hasattr(field_cls, "__args__") and index >= 0:
667-
field_cls = field_cls.__args__[index]
667+
if field_cls.__args__ is not None:
668+
field_cls = field_cls.__args__[index]
668669
return field_cls
669670

670671
def _get_field_default(self, field_name):

src/betterproto/grpc/grpclib_client.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
Type,
1414
Union,
1515
)
16-
from .._types import ST, T
16+
from betterproto._types import ST, T
1717

1818
if TYPE_CHECKING:
19-
from grpclib._typing import IProtoMessage
2019
from grpclib.client import Channel
2120
from grpclib.metadata import Deadline
2221

2322

2423
_Value = Union[str, bytes]
2524
_MetadataLike = Union[Mapping[str, _Value], Collection[Tuple[str, _Value]]]
26-
_MessageSource = Union[Iterable["IProtoMessage"], AsyncIterable["IProtoMessage"]]
25+
_MessageLike = Union[T, ST]
26+
_MessageSource = Union[Iterable[ST], AsyncIterable[ST]]
2727

2828

2929
class ServiceStub(ABC):
@@ -59,7 +59,7 @@ def __resolve_request_kwargs(
5959
async def _unary_unary(
6060
self,
6161
route: str,
62-
request: "IProtoMessage",
62+
request: _MessageLike,
6363
response_type: Type[T],
6464
*,
6565
timeout: Optional[float] = None,
@@ -82,7 +82,7 @@ async def _unary_unary(
8282
async def _unary_stream(
8383
self,
8484
route: str,
85-
request: "IProtoMessage",
85+
request: _MessageLike,
8686
response_type: Type[T],
8787
*,
8888
timeout: Optional[float] = None,

0 commit comments

Comments
 (0)