【发布时间】:2018-05-17 20:17:41
【问题描述】:
我的 mypy 有问题
我有这样的代码:
func(arg1, arg2, arg3=0.0, arg4=0.0)
# type: (float, float, float, float) -> float
# do something and return float.
dict_with_other_arguments = {arg3: 0.5, arg4: 1.4}
a = func(arg1, arg2, **dict_with_other_arguments)
问题是 mypy 不检查字典中的类型,而是出现如下错误: 错误:“func”的参数 3 具有不兼容的类型“**Dict[str, float]”;预期“浮动”
任何想法如何在不更改代码的情况下解决此问题?
【问题讨论】:
-
您能否更新您的帖子,使其包含您的问题的minimal, complete, and verifiable example?
-
当然,编辑得更清楚了。
-
我无法重现您的问题,抱歉。例如,Mypy 对 this program 非常满意。 (请注意,我稍微调整了您的示例以确保一切都可以在运行时实际工作)。
-
@Michael0x2a 我提供了here 问题的示例,它似乎在涉及多种类型时发生。
-
是的,这可能是问题所在。
标签: python dictionary mypy