damd
damd

Reputation: 6997

What does this warning in PyCharm mean?

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.

Upvotes: 6

Views: 11755

Answers (2)

Artem Sobolev
Artem Sobolev

Reputation: 6089

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))

Upvotes: 6

Ffisegydd
Ffisegydd

Reputation: 53718

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.

Upvotes: 8

Related Questions