Pycharm: Expected type 'Integral', got 'str' instead

pycharm, python

Solution

Based on the 'more...' screenshot, it looks like Pycharm might be interpreting the map() as though the two terms around the comma are both part of the lambda, i.e. the lambda just returns a 2-tuple instead of treating it as two parameters to the map() function.

Things to try:

- Add parentheses inside the map()

- look for redefinitions of the map() builtin itself that might be confusing Pycharm

EDIT

You inspired me to go learn more about Python and Pycharm. :)

It looks like Pycharm is happier with using a list comprehension than with `map()`. Using this sample data:

data = {
    'data': {
        'children': [
            {'data': {'url': 'http://1.com/', }, },
            {'data': {'url': 'http://2.com/', }, },
        ]
    },
}

if you write the code like you did, then you get the error:

items = map(lambda children: children['data'], data['data']['children'])
for item in items:
    print item['url']  # Pycharm shows warning on 'url'

But if you use a list comprehension instead, then Pycharm is happy:

items = [x['data'] for x in data['data']['children']]
for item in items:
    print item['url']  # No warning from Pycharm

And the output is the same for both.

ISTR reading that list comprehensions are preferred over `map()` nowadays anyway, so maybe Pycharm is nudging us in that direction?

Problem

I just installed PyCharm 3.4 and get some new warnings. Not just here but in many places. Code is fine of course. Can someone translate what PyCharm trying to tell me and how to silence this messages? more...

Original source