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

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

对于这段代码:

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 screenshot

我是否丢失了某些东西,或者这是推导类型的简单案例,而PyCharm在这里出错了?

python pycharm typing
1个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.