danielgtaylor / danielgtaylor/python-betterproto
Add a default values for rpc with empty message
- 主要语言
- Python
- 星标
- 1.8k
- 派生
- 234
- PR 合并指标
- 30 天内没有已合并 PR
描述
### The Problem
Sometimes, it is needed to declare RPCs that take no parameter. However, it is not possible in gRPC. In such a situation, it is needed to either create an empty message type, or to use `google.protobuf.Empty` ( https://stackoverflow.com/questions/29687243/protobuf-rpc-service-method-without-parameters ).
However, this is not convenient for the final user: an empty message need to be created and passed to the method each time. It also makes it necessary to add potentially long imports.
### The Ideal Solution
To make this easier, it would be better to add a default value for the parameter containing the request when it is possible. I see two possibilities:
- Add the default value only for `google.protobug.Empty`
- Add the default value for all the messages who have no field at all
I think the second solution would be better as it is common to define empty messages in such situations. I can make a PR if you agree, I already have a working version locally.
### The Current Solution
Currently, it is necessary for the user to import by hand `from betterproto.lib.std.google.protobuf import Empty` or the custom message, which is not convenient.
The feature would turn:
```python
from betterproto.lib.std.google.protobuf import Empty
answer = TestStub().call(Empty())
```
To something like:
```python
answer = TestStub().call()
```
贡献指南
调研方向
issue 中没有确定任何文件或测试。首先定位生成的 Python RPC 方法签名,以及当前对 google.protobuf.Empty 或无字段消息的处理;完成的标准是:无需传入参数即可调用空消息 RPC,同时现有的显式消息调用继续正常工作。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- grpc, python
- 领域
- api, backend-api-design
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100