Adjustment: The rule only detects dictionary access via [x], not .get(x). It should detect both.
Explanation
I noticed that if you misread the warning you might simply replace [x] with .get(x), and that would silence the warning without actually fixing the problem it is warning you about.
Example
This is an example where the mentioned rule currently does not work:
foo = ''
if 'a' in my_dict:
foo = my_dict.get('a')
(the "correct" way to write this is actually foo = my_dict.get('a', ''))
Desired change
[x]
, not.get(x)
. It should detect both.Explanation
I noticed that if you misread the warning you might simply replace
[x]
with.get(x)
, and that would silence the warning without actually fixing the problem it is warning you about.Example
This is an example where the mentioned rule currently does not work:
(the "correct" way to write this is actually
foo = my_dict.get('a', '')
)