Type error on server-side unary-unary handler code
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- grpc, python
- Lĩnh vực
- backend-api-design, devtools
Hướng nghiên cứu
Bắt đầu với reproduce.proto và reproduce/init.py được sinh, tập trung vào XBase.__rpc_y và lệnh gọi self.y. Chạy lại protoc bằng lệnh được hiển thị, sau đó chạy mypy reproduce/init.py để tái hiện lỗi. Được xem là hoàn tất khi handler được sinh vượt qua mypy mà không có lỗi đối số Optional[Z] không tương thích.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 1.8k
- Fork
- 235
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của danielgtaylor/python-betterproto
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
-
bug investigation needed
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
-
bug investigation needed
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
-
bug investigation needed
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
danielgtaylor/python-betterproto#676 · 3 bình luận ·
Tất cả issue của danielgtaylor/python-betterproto
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
zach-blumenfeld/aip#13 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
nathanmarlor/foxess_modbus#1287 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
bug good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
OpenLakeForge/openlakeforge#498 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue hacktoberfest help wanted python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Exact onnxruntime==1.27.0 core pin makes Pipecat-based apps uninstallable from the dashboardĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 69/100
pollen-robotics/reachy_mini#1493 ·
Maintainer thường phản hồi trong vòng 1 ngày