我对 if 进行了验证,mypy 告诉我该错误:“or”的右操作数永远不会被评估[无法访问]。
if category is None and (
category["Description"] is None
or category["Description"] == ""
):
您可以帮我解决这个问题吗,谢谢
从技术上讲,只有当
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
或 ""