Skip to content

Commit

Permalink
More accurately represent request parameter in grpc functions (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunn1313 authored Jan 18, 2022
1 parent fcc5a49 commit cb90fcb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
- Support `*_FIELD_NUMBER` for extensions
- Bump types-protobuf dependency to 3.19
- Support DESCRIPTOR: ServiceDescriptor in py generic services
- More accurately represent method names in py generic services (done -> callback, self -> inst)
- More accurately represent method names in py generic services (done -> callback, self -> inst)
- More accurately represent method names in grpc services (`request` -> `request_iterator`)
- Internal: Get tests to pass on pure-python protobuf impl (minor semantic differences)
- Internal: Bump pyright in testing to 1.1.206
- Internal: Use stubtest to validate generated stubs match generated runtime
Expand Down
6 changes: 5 additions & 1 deletion mypy_protobuf/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,11 @@ def write_grpc_methods(
l("@{}", self._import("abc", "abstractmethod"))
l("def {}(self,", method.name)
with self._indent():
l("request: {},", self._input_type(method))
input_name = (
"request_iterator" if method.client_streaming else "request"
)
input_type = self._input_type(method)
l(f"{input_name}: {input_type},")
l("context: {},", self._import("grpc", "ServicerContext"))
l(
") -> {}:{}",
Expand Down
3 changes: 2 additions & 1 deletion stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ testproto.nested.nested_pb2.AnotherNested.NestedMessage._?NestedEnum2(EnumTypeWr

# Some issues with our service stubs for now
testproto.test_pb2.ATestService.*
testproto.grpc.dummy_pb2_grpc.DummyServiceServicer.*

# Part of an "EXPERIMENTAL API" according to comment. Not documented.
testproto.grpc.dummy_pb2_grpc.DummyService
testproto.grpc.import_pb2_grpc.SimpleService
4 changes: 2 additions & 2 deletions test/generated/testproto/grpc/dummy_pb2_grpc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ class DummyServiceServicer(metaclass=abc.ABCMeta):

@abc.abstractmethod
def StreamUnary(self,
request: typing.Iterator[testproto.grpc.dummy_pb2.DummyRequest],
request_iterator: typing.Iterator[testproto.grpc.dummy_pb2.DummyRequest],
context: grpc.ServicerContext,
) -> testproto.grpc.dummy_pb2.DummyReply:
"""StreamUnary"""
pass

@abc.abstractmethod
def StreamStream(self,
request: typing.Iterator[testproto.grpc.dummy_pb2.DummyRequest],
request_iterator: typing.Iterator[testproto.grpc.dummy_pb2.DummyRequest],
context: grpc.ServicerContext,
) -> typing.Iterator[testproto.grpc.dummy_pb2.DummyReply]:
"""StreamStream"""
Expand Down

0 comments on commit cb90fcb

Please sign in to comment.