【发布时间】:2021-03-28 05:34:02
【问题描述】:
如果我输入插槽:
class Foo:
__slots__: Tuple[()] = tuple()
然后,在严格模式下,mypy (0.812) 告诉我:
Incompatible types in assignment (expression has type "Tuple[<nothing>, ...]", variable has type "Tuple[]")
我会写:
__slots__: Tuple[()] = cast(Tuple[()], tuple())
但这很丑。这样做的规范方法是什么? Tuple[<nothing>, ...] 中的 mypy 是什么意思?元组是不可变的,所以肯定一个空元组不应该是......可变数量的无......?
【问题讨论】:
-
更重要的是:为什么你想这样做?
__slots__ = ()将被正确推断。 -
啊——对……我以为
()和tuple()是一回事。