为什么 PyCharm 错误地猜测了 dict_items 列表的类型?

Why does PyCharm incorrectly guess type for a list of dict_items?

对于这段代码:

from typing import Dict, List, Tuple, Any


def test(d: Dict[int, Any]):
    item_list: List[Tuple[int, Any]] = list(d.items())

PyCharm 由于某种原因猜测 item_list 将是 List[int] 类型:

我是不是遗漏了什么,或者这是一个非常简单的推导类型的例子,PyCharm 在这里错了吗?

您的代码是正确的。这是 PyCharm 中的错误。 您可以在此处的错误跟踪器上跟踪其状态: Incorrect type inference of dict.items()。考虑对其进行投票,以便尽快修复它。