How do I specify this kind of variable argument tuple with python typing?

怎甘沉沦 提交于 2019-12-02 02:14:34

there currently isn't an annotation which can represent the addition of a fixed-length tuple with a variable length tuple.

here's some code I used to determine how mypy's inference would handle something like this:

from typing import Tuple

x: Tuple[int, ...]
y = ('hi', *x)
z = (*x,)
reveal_type(y)
reveal_type(z)

and output:

$ mypy t.py
t.py:6: error: Revealed type is 'builtins.tuple[builtins.object*]'
t.py:7: error: Revealed type is 'builtins.tuple[builtins.int*]'

despite knowing that it's a variable-length int tuple it decays to object.

You may want to refactor your code to use Tuple[SignalNode, Tuple[Any, ...]] instead

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!