添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
暴走的树叶  ·  n2adr-sdr@groups.io | ...·  2 天前    · 
睡不着的盒饭  ·  xml.sax.saxutils --- ...·  昨天    · 
才高八斗的豆浆  ·  [python] ...·  8 小时前    · 
狂野的啄木鸟  ·  A conditional Version ...·  5 月前    · 
没有腹肌的电影票  ·  python ...·  6 月前    · 
爱旅游的荔枝  ·  GitHub - ...·  7 月前    · 
大鼻子的鸡蛋  ·  adcfgclone.pl Fails ...·  8 月前    · 

Python – Why is this warning “Expected type ‘int’ (matched generic type ‘_T’), got ‘Dict[str, None]’ instead”

pycharm python

Please watch carefully the question and carefully the answers of this and you'll see it's not a duplicate , especially because they dont answer my question.

Try to make a new empty project, and add this code. It works fine without warnings:

game_data = {'boats': [], }
game_data['boats'].append({'name': None})

Now change it to:

game_data = {'boats': [], 'width': None, 'height': None, }
game_data['boats'].append({'name': None})

Still no warnings.
And change again to:

w = 12
game_data = {'boats': [], 'width': None, 'height': w, }
game_data['boats'].append({'name': None})

And now you'll get:

Expected type 'int' (matched generic type '_T'), got 'Dict[str, None]' instead

Am I the only one to have this? And why is this? Is there a solution to make this warning go away?

My guess would be the analytics that give this warning are not sharp enough.

The value type for

game_data = {'boats': [], 'width': None, 'height': None} 

can not be determined.

The first "real" value you put in is an int:

w = 12
game_data = {'boats': [], 'width': None, 'height': w}

So PyCharm assumes that this is a dict(string->int).

Then you add a inner dict as value to your empty list:

game_data['boats'].append({'name': None})

So now it has a dict(string->int) that suddenly gets to be a mixed thing and warns you.

Thats about the same as what What does this warning in PyCharm mean? is about: adding int into a list of strings using pycharm as IDE.

As to how to get rid of the warning: Jetbrains Resharper is very configurable, I guess pycharm will be as well. This documentation https://www.jetbrains.com/help/pycharm/configuring-inspection-severities.html#severity might help you configure the severity down - if not I am sure the support of Jetbrains is eager to help you out - they were whenever I had problems using resharper.