Type error on server-side unary-unary handler code
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- grpc, python
调研方向
从 reproduce.proto 和生成的 reproduce/init.py 开始,重点关注 XBase.__rpc_y 以及对 self.y 的调用。使用所示命令重新运行 protoc,然后运行 mypy reproduce/init.py 以重现错误。当生成的 handler 通过 mypy 且不再出现不兼容的 Optional[Z] 参数错误时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Summary
Incompatible type error on generated unary-unary handler code.
Reproduction Steps
Write reproduce.proto:
syntax = "proto3";
package reproduce;
service X {
rpc Y(Z) returns (Z) {}
}
message Z {}
Generate code with betterproto==2.0.0b6:
$ protoc -I . --python_betterproto_out=. reproduce.proto
Verify type error by mypy==1.8.0:
$ mypy reproduce/__init__.py
Expected Results
No mypy error
Actual Results
reproduce/__init__.py:55: error: Argument 1 to "y" of "XBase" has incompatible type "Z | None"; expected "Z" [arg-type]
Found 1 error in 1 file (checked 1 source file)
Here's a chunk of the generated code which has the type error:
class XBase(ServiceBase):
async def __rpc_y(self, stream: "grpclib.server.Stream[Z, Z]") -> None:
request = await stream.recv_message()
response = await self.y(request)
# ^^^^^^^ Argument 1 to "y" of "XBase" has incompatible type "Z | None"; expected "Z" [arg-type]
await stream.send_message(response)
stream.recv_message() returns Optional[Z] so request might be None when the connection closes. But self.y() doesn't accept None because it's parameter type is Z but not Optional[Z].
System Information
libprotoc 25.3
Python 3.11.6
Name: betterproto
Version: 2.0.0b6
Summary: A better Protobuf / gRPC generator & library
Home-page: https://github.com/danielgtaylor/python-betterproto
Author: Daniel G. Taylor
Author-email: [email protected]
License: MIT
Location: .../.venv/lib/python3.11/site-packages
Requires: grpclib, python-dateutil
Required-by:
Name: grpclib
Version: 0.4.7
Summary: Pure-Python gRPC implementation for asyncio
Home-page: https://github.com/vmagamedov/grpclib
Author: Vladimir Magamedov
Author-email: [email protected]
License: BSD-3-Clause
Location: .../.venv/lib/python3.11/site-packages
Requires: h2, multidict
Required-by: betterproto
Name: mypy
Version: 1.8.0
Summary: Optional static typing for Python
Home-page: https://www.mypy-lang.org/
Author: Jukka Lehtosalo
Author-email: [email protected]
License: MIT
Location: .../.venv/lib/python3.11/site-packages
Requires: mypy-extensions, typing-extensions
Required-by:
Checklist
- I have searched the issues for duplicates.
- I have shown the entire traceback, if possible.
- I have verified this issue occurs on the latest prelease of betterproto which can be installed using
pip install -U --pre betterproto, if possible.
- 主要语言
- Python
- 星标
- 1.8k
- 派生
- 235
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
danielgtaylor/python-betterproto 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 55/100
-
难度 5/5 一周以上 新手友好度 15/100
-
bug investigation needed
难度 3/5 1-2 天 新手友好度 42/100
-
bug investigation needed
难度 3/5 1-2 天 新手友好度 45/100
-
bug investigation needed
难度 4/5 3-5 天 新手友好度 38/100
danielgtaylor/python-betterproto#676 · 3 条评论 ·
查看 danielgtaylor/python-betterproto 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 77/100
developmentseed/titiler-cmr#250 · 1 条评论 ·
维护者通常 1 天内回复
-
[Bug]: IndexHandler.post crashes with HTTP 500 on malformed payloads, missing credentials, or when login is disabled可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 6 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
cookiecutter/cookiecutter-django#6999 ·
维护者通常 1 天内回复
-
fix: @_helpers.positional raises TypeError when decorating functions without default arguments可能已有人在做 @codeXsidd 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 88/100
googleapis/google-api-python-client#2845 ·
维护者通常 1 天内回复
-
github_actions
难度 2/5 1-3 小时 新手友好度 65/100
collective/icalendar#2003 · 1 条评论 ·
维护者通常 1 天内回复