错误:“or”的右操作数从未被评估[无法访问]

问题描述 投票:0回答:1

我对 if 进行了验证,mypy 告诉我该错误:“or”的右操作数永远不会被评估[无法访问]。

if category is None and (
    category["Description"] is None
    or category["Description"] == ""
):

您可以帮我解决这个问题吗,谢谢

python mypy
1个回答
0
投票

从技术上讲,只有当

category
是一个字典而不是
None

时,第二部分才有意义
if category is not None and 
   ("Description" in category and 
    category["Description"] in [None, '']):
  ...

"Description" in category
确保键
"Description"
存在于字典中
category

category["Description"] in [None, ""]
检查
category["Description"]
是否为
None
""

© www.soinside.com 2019 - 2024. All rights reserved.