【发布时间】:2020-12-31 12:46:22
【问题描述】:
如果我在使用 mypy 时遇到错误,我将不胜感激。
我的函数看起来像:
def get_result(
f1: float,
l: List[float],
d: Dict[float, Optional[List[str]]],
f2: float,
s: str
) -> Optional[List[str]]:
if f1 is in l:
if d[f2] is None:
return [s]
else:
return sorted(d[f2] + [s])
return d[f2]
然而,mypy 为return sorted(d[f2] + [s]) 行提供了error: Unsupported left operand type for + ("None") 和note: Left operand is of type "Optional[List[str]]",即使我在值为None 时提前返回。
非常感谢任何帮助。
【问题讨论】:
标签: python mypy python-typing