Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this warning in PyCharm mean?

Tags:

python

pycharm

I'm writing a Uno game in Python and I'm currently setting up a Uno deck.

_VALID_FACES = ['skip', 'draw2', 'reverse', 'wild', 'wild4'] + range(10)

I think this should be just fine and dandy, no problem. However, PyCharm insists on this error:

Expected type list[str] (matched generic type 'list[T]'), got 'list[int]' instead

Now I'm not entirely sure what this means. Any ideas? The code runs, but the warning is still there in PyCharm.

like image 496
damd Avatar asked Jan 06 '15 10:01

damd


2 Answers

PyCharm reads your code and tries to guess what you're doing, then if you do something contrary to what it thinks you should be doing, it will warn you. This is useful when you have a large codebase and you accidentally do something stupid, but can be annoying when you know exactly what you're doing.

In this case, you've got a list full of strings, and you're adding a list of integers to it. PyCharm is surprised at this, thinking you'd only be having strings in your list, not a mixture of strings and integers.

You should be able to safely ignore it.

like image 63
Ffisegydd Avatar answered Oct 03 '22 02:10

Ffisegydd


Though you can have list of strings and ints in python, it's preferable to keep list elements' types consistent. In your example you can convert all elements to strings:

_VALID_FACES = ['skip', 'draw2', 'reverse', 'wild', 'wild4'] + map(str, range(10))
like image 40
Artem Sobolev Avatar answered Oct 03 '22 04:10

Artem Sobolev