python/mypy 使用元组进行详尽检查

问题描述 投票:0回答:1

我正在尝试匹配

Union
的值并让 mypy 执行详尽检查。这是一个最小的工作示例:

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]

这表明值

case
缺少
tuple[<nothing>, <nothing>]
。 我一直无法找到任何有关匹配元组的限制的信息。我错过了什么还是这是我的错误?

python match mypy
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.