【发布时间】:2022-01-14 06:23:29
【问题描述】:
我有一个如下所示的 python 模块:
import numpy as np
def test(order: str = 'C') -> np.ndarray:
return np.array([1,2,3]).reshape((1,2), order = order)
用 mypy 评估它会返回错误和注释
error: No overload variant of "reshape" of "_ArrayOrScalarCommon" matches argument types "Tuple[int, int]", "str"
note: Possible overload variants:
note: def reshape(self, Sequence[int], *, order: Union[Literal['A'], Literal['C'], Literal['F'], None] = ...) -> ndarray
note: def reshape(self, *shape: int, order: Union[Literal['A'], Literal['C'], Literal['F'], None] = ...) -> ndarray
将函数调用中的部分 order = order 替换为 order = 'C' 可以防止发生此错误。如果我选择将此参数作为函数参数传递,为什么 mypy 会出现问题?
【问题讨论】:
标签: python type-hinting mypy