问题描述
我是Python静态键入模块mypy
的新手。我试图将整数和浮点数附加到一个数组,我将其静态键入为Real。但是mypy
说它们是与Real不兼容的类型。我以为int和float是Real的子类型?
data : List[Real] = []
with open(path,'r') as file:
for line in file:
line = line.strip()
if subject == 'time':
data.append(float(line))
else:
data.append(int(line))
错误消息:
graph.py:56: error: Argument 1 to "append" of "list" has incompatible type "float"; expected "Real"
graph.py:58: error: Argument 1 to "append" of "list" has incompatible type "int"; expected "Real"
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)