【发布时间】:2018-02-27 12:27:38
【问题描述】:
from typing import Tuple
def test_1(inp1: Tuple[int, int, int]) -> None:
pass
def test_2(inp2: Tuple[int, int, int]) -> None:
test_tuple = tuple(e for e in inp2)
reveal_type(test_tuple)
test_1(test_tuple)
在上述代码上运行 mypy 时,我得到:
error: Argument 1 to "test_1" has incompatible type "Tuple[int, ...]"; expected "Tuple[int, int, int]"
test_tuple 是否不能保证有 3 个 int 元素? mypy 不处理这样的列表推导还是有另一种在这里定义类型的方法?
【问题讨论】:
标签: python python-3.x type-hinting mypy python-typing