Skip to content

feat: add type annotations to wrapped grpc calls #554

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 16 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixed tests
  • Loading branch information
daniel-sanche committed Nov 17, 2023
commit 202697441ae923f4f2b8b1d229bebc1f39e44619
6 changes: 3 additions & 3 deletions google/api_core/grpc_helpers_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async def wait_for_connection(self):
except grpc.RpcError as rpc_error:
raise exceptions.from_grpc_error(rpc_error) from rpc_error

class _WrappedUnaryResponseMixin(_WrappedCall, Generic[U]):
class _WrappedUnaryResponseMixin(Generic[U], _WrappedCall):
def __await__(self) -> Generator[Any, None, U]:
try:
response = yield from self._call.__await__()
Expand All @@ -90,7 +90,7 @@ def __await__(self) -> Generator[Any, None, U]:
raise exceptions.from_grpc_error(rpc_error) from rpc_error


class _WrappedStreamResponseMixin(_WrappedCall, Generic[S]):
class _WrappedStreamResponseMixin(Generic[S], _WrappedCall):
def __init__(self):
self._wrapped_async_generator = None

Expand Down Expand Up @@ -154,7 +154,7 @@ class _WrappedStreamStreamCall(


# public type denoting the return type of streaming gapic calls
AwaitableGrpcAsyncStream = Union[_WrappedUnaryStreamCall[S], _WrappedStreamStreamCall[S]]
AwaitableGrpcStream = Union[_WrappedUnaryStreamCall[S], _WrappedStreamStreamCall[S]]
# public type denoting the return type of unary gapic calls
AwaitableGrpcCall = Union[_WrappedUnaryUnaryCall[U], _WrappedStreamUnaryCall[U]]

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_grpc_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ def test_wrap_unary_errors():
assert exc_info.value.response == grpc_error


class Test_StreamingResponseIterator:
class TestGrpcStream:
@staticmethod
def _make_wrapped(*items):
return iter(items)

@staticmethod
def _make_one(wrapped, **kw):
return grpc_helpers._StreamingResponseIterator(wrapped, **kw)
return grpc_helpers.GrpcStream(wrapped, **kw)

def test_ctor_defaults(self):
wrapped = self._make_wrapped("a", "b", "c")
Expand Down