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...
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:
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?
You can also get rid of this notification if you get the value from the dictionary with get()
. This should work:
fresh_urls = {item.get('url') for item in items}
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