生成grpc代码中的Python类型提示的方法

huangapple go评论66阅读模式
英文:

How to generate python type hints in generated grpc code

问题

PEP 兼容的类型提示是否可以自动添加到生成的源代码中,或者为 Python 和 gRPC 动态创建?具体来说,在基础教程中,在客户端部分的 feature = stub.GetFeature(point),我希望我的 IDE 知道并检查 point 的类型是 Point*_pb2.py 中,并且 feature 的类型是具有属性 location: PointFeature。谢谢。

英文:

Can PEP compliant type hints be automatically added to generated source code, or dynamically created, for python and gRPC? Specifically in the basics tutorial in the client section for feature = stub.GetFeature(point) I would like my IDE to know and check that point is type Point in the *_pb2.py and feature is type Feature with an attribute location: Point. Thank you.

答案1

得分: 1

Type hints aren't yet (!?) available for Python gRPC, see Issue 29041

You can generate type hints for the Protobuf messages only using the --pyi_out=${PWD} flag when running protoc directly or indirectly with python3 -m grpc.tools.protoc

英文:

Type hints aren't yet (!?) available for Python gRPC, see Issue 29041

You can generate type hints for the Protobuf messages only using the --pyi_out=${PWD} flag when running protoc directly or indirectly with python3 -m grpc.tools.protoc

答案2

得分: 1

对于生成的protobuf文件(*_pb2.py),我们有一份正在审查中的PR,以添加pyi文件。至于gRPC Python的一般情况,我目前正在处理它,预计将在本季度末完成。

英文:

For protubuf generated files (*_pb2.py), we have a PR in review to add pyi files. And for gRPC Python in general, I'm currently working on it and it should be finished by end of this quarter.

huangapple
  • 本文由 发表于 2023年5月11日 02:11:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76221461.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定