我有一个列表列表,每个列表都包含一个文件对象和一个字符串列表:
sample = [
[fileobject1, ['hello', 'world']],
[fileobject2, ['something', 'else']]
]
我输入这样注释sample:
List[List[Union[IO, List[str]]]]
进一步在我的代码中,我在内部列表的第一个 (0) 和第二个 (1) 条目上调用了一些方法。
例如像这样清除最内部的列表:
entry[1].clear()
代码运行良好,但 mypy 正确地抱怨:
Item "IO[Any]" of "Union[IO[Any], List[str]]" has no attribute "clear"
我将如何正确键入注释?也许一起使用不同的数据结构?