Skip to content

Fix static type checking for grpclib client #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/betterproto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions src/betterproto/grpc/grpclib_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down