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

if-else-block-instead-of-if-exp autofix predates the desired if-else-block-instead-of-dict-get autofix #4932

Closed
tjkuson opened this issue Jun 7, 2023 · 0 comments · Fixed by #4944
Assignees

Comments

@tjkuson
Copy link
Contributor

tjkuson commented Jun 7, 2023

Expected behaviour

ruff check --fix --select SIM . should autofix

obj: dict = ...
key = ...

if key in obj:
    value = obj[key]
else:
    value = "Not found"

to this:

obj: dict = ...
key = ...

value = obj.get(key, "Not found")

Actual behaviour

ruff check --fix --select SIM . autofixes the above code to

obj: dict = ...
key = ...

value = obj[key] if key in obj else "Not found"

This happens because if-else-block-instead-of-if-exp (SIM108) autofixes before if-else-block-instead-of-dict-get (SIM401), and SIM401 does not flag violations in ternary operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants