pyright (通过vim中的coc和VSCode中的pylance )将属性的类型标识为Field (当它是str )。
CreateKeyRingRequest是从google的proto.message.Message派生出来的,从文档中可以清楚地将parent识别为str
| 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
码
from google.cloud import kms_v1
request = kms_v1.CreateKeyRingRequest() request.parent = "test"误差
[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

发布于 2022-07-26 15:57:34
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。
下面是您在运行任何代码之前需要做的项目设置的快速发车。
https://stackoverflow.com/questions/73126100
复制相似问题