MartinThoma / flake8-simplify

❄ A flake8 plugin that helps you to simplify code
MIT License
186 stars 19 forks source link

[Adjust Rule] SIM908 does not detect `.get()` #138

Open MetRonnie opened 2 years ago

MetRonnie commented 2 years ago

Desired change

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', ''))