Not sure why I get this unexplained type error



I'm running into a strange editor warning when running Pycharm community 2018.3 and Python 2.7.  I've reduced it down to this code snippet:

p = [None] * 4

p[0] = 3

Pycharm gives the following warning on the array index 0:

Unexpected type(s):

(int, int)

Possible types:

(int, None)

(slice, Iterable[None])

The warning goes away if I change the first line to p = [None, None, None, None]

Does anyone have an idea why this is happening?  Thanks!


1 comment


We only support it for literals:

[None, None, ...] -- literal

[None] * 4 -- not literal

A workaround is to define types manually.


Please sign in to leave a comment.