Search code examples
pythonpycharm

Unexpected type(s): (int, int) Possible type(s): (SupportsIndex, None) (slice, Iterable[None])


What's wrong with this code:

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]

In PyCharm it issues a warning;

Unexpected type(s): (int, int) Possible type(s): (SupportsIndex, None) (slice, Iterable[None])

But the script runs just fine and this code works exactly as I expected. I don't like warnings in my IDE though, any quick fixes?


Solution

  • This warning is solved by updating to PyCharm to 2021.2.2.

    It seems to be a bug in earlier versions of the IDE's static type checker.

    One user reported in the comments that this bug regressed in the PyCharm 2021.2.3 release.

    I just tested it again using PyCharm 2022.1 Professional Edition and the bug has again been solved. Here's a screenshot:

    screenshot of code in IDE's editor window