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.
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.
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With