如何修复 pylint 错误 "Unnecessary use of a comprehension"

How to fix pylint error "Unnecessary use of a comprehension"

使用 python 3.8.6 和 pylint 2.4.4 以下代码会产生 pylint 错误(或建议)

R1721: Unnecessary use of a comprehension (unnecessary-comprehension)

这是代码:

dict1 = {
    "A": "This is A",
    "B": "This is B"
}
bools = [True, False]

dict2 = {key: value for key, value in zip(dict1.keys(), bools)}

如何修改代码以删除此 R1721 消息?

dict 构造函数采用 key/value 对的可迭代,因此正如消息所说,此处不需要字典理解。

dict2 = dict(zip(dict1.keys(), bools))