首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pyright将类型标识为字段而不是str。

pyright将类型标识为字段而不是str。
EN

Stack Overflow用户
提问于 2022-07-26 15:28:05
回答 1查看 178关注 0票数 -1

pyright (通过vim中的coc和VSCode中的pylance )将属性的类型标识为Field (当它是str )。

CreateKeyRingRequest是从google的proto.message.Message派生出来的,从文档中可以清楚地将parent识别为str

代码语言:javascript
复制
 |  Attributes:
 |      parent (str):
 |          Required. The resource name of the location associated with
 |          the [KeyRings][google.cloud.kms.v1.KeyRing], in the format
 |          ``projects/*/locations/*``.

版本

coc.nvim coc-pyright 1.1.262和Pyright 1.1.263

NVIM v0.8.0-dev+3-g3f2e9298 b

代码语言:javascript
复制
from google.cloud import kms_v1
request = kms_v1.CreateKeyRingRequest()                                                                                                                                 request.parent = "test"

误差

代码语言:javascript
复制
[PyRight reportGeneralTypeIssues]
Cannot assign member "parent" for type "CreateKeyRingRequest"
Expression of type "Literal['test']" cannot be assigned to member "parent"...
"Literal['test']" is incompatible with type Field

EN

回答 1

Stack Overflow用户

发布于 2022-07-26 15:57:34

看着github上的源代码

代码语言:javascript
复制
class CreateCryptoKeyRequest(proto.Message):
    parent = proto.Field(proto.STRING, number=1,)
    crypto_key_id = proto.Field(proto.STRING, number=2,)
    crypto_key = proto.Field(proto.MESSAGE, number=3, message=resources.CryptoKey,)
    skip_initial_version_creation = proto.Field(proto.BOOL, number=5,)

文档称它为字符串,但在上下文中,它是一个proto字段,是一个字符串。在原型协议上读一下。我不确定您是否熟悉protobuf,但认为它是SOAP的一个更有效的版本(在计算机之间发送方法调用,但使用二进制格式而不是xml文本)。因此,这里的父属性不是一个普通的python字符串,它是位于proto.STRING消息位置1的一个CreateCryptoKeyRequest

下面是一个使用kms库的一堆客户端代码示例

下面是一个创建和发送生成代码示例消息的CreateCryptoKeyRequest

下面是您在运行任何代码之前需要做的项目设置的快速发车

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73126100

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档