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

Question:

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?

Asked By: Julian

||

Answers:

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

Answered By: bad_coder

Bom dia!
no meu estava acontecendo a mesma coisa, eu só mudei a declaração da variável.
estava assim: dados = []
mudei para: dados = dict()

Answered By: Monique Vasconcelos
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.