Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce .get with dicts over in checks #998

Closed
sobolevn opened this issue Nov 12, 2019 · 1 comment
Closed

Enforce .get with dicts over in checks #998

sobolevn opened this issue Nov 12, 2019 · 1 comment
Assignees
Labels
rule request Adding a new rule
Milestone

Comments

@sobolevn
Copy link
Member

sobolevn commented Nov 12, 2019

Rule request

Thesis

When we see a code like:

if 'inr' in currency_map:
    indian_currency_name = currency_map['inr']
else:
    indian_currency_name = 'undefined'

We should raise a refactoring violation. That's how it should be:

currency_map = {'usd': 'US Dollar'}
indian_currency_name = currency_map.get('inr', 'undefined')

The second version is more pythonic.

Origin: https://deepsource.io/blog/8-new-python-antipatterns

@sobolevn sobolevn added the rule request Adding a new rule label Nov 12, 2019
@sobolevn
Copy link
Member Author

@sobolevn sobolevn added this to the Version 0.13 milestone Nov 15, 2019
@sobolevn sobolevn self-assigned this Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule request Adding a new rule
Projects
None yet
Development

No branches or pull requests

1 participant