意外类型:(int, int) 可能类型:(SupportsIndex, None) (slice, Iterable[None])

Jul*_*ian 5 python pycharm

这段代码有什么问题:

split_list = [3600, 3600, 3600, 3600, 3600, 3600, 3600, 3600, 45]
split_list2 = [None, None, None, None, None, None, None, None, None, None, None, None]
result = [3600, 3600, 3600, 3600, 3600, 3600, 3600, 3600, 45, None, None, None]

for i in range(len(split_list)):
    split_list2[i] = split_list[i]
Run Code Online (Sandbox Code Playgroud)

在 PyCharm 中它会发出警告;

意外类型:(int, int) 可能类型:(SupportsIndex, None) (slice, Iterable[None])

但脚本运行得很好,并且这段代码完全按照我的预期工作。不过,我不喜欢 IDE 中出现警告,有什么快速修复方法吗?

bad*_*der 5

通过将 PyCharm 更新到 2021.2.2 可以解决此警告。

这似乎是 IDE 静态类型检查器早期版本中的一个错误。

一位用户在评论中报告说,该错误在 PyCharm 2021.2.3 版本中得到了回归。

我刚刚使用PyCharm 2022.1专业版再次测试,该错误再次得到解决。这是一个屏幕截图:

IDE 编辑器窗口中的代码屏幕截图

  • 自 2023 年 2 月 1 日(社区版)起该错误再次出现 (3认同)