提问人:Sebastiaan 提问时间:10/5/2023 更新时间:10/5/2023 访问量:55
python/mypy 穷举检查元组
python/mypy exhaustiveness checking with tuples
问:
我正在尝试匹配 a 的值,并让 mypy 执行详尽性检查。下面是一个最小的工作示例:Union
t: tuple[int, float] | str
match t:
case str():
print("found str")
case (int(), float()):
print("found tuple")
case _ as unreachable:
assert_never(unreachable)
我希望它能通过 mypy 检查,因为这两个选项都包括在内。但是我收到一个错误
Argument 1 to "assert_never" has incompatible type "tuple[<nothing>, <nothing>]"; expected "NoReturn" [arg-type]
这将表明缺少值 。
我一直找不到任何关于匹配元组限制的信息。是我遗漏了什么,还是这是一个mypy错误?case
tuple[<nothing>, <nothing>]
答:
评论
Never
unreachable