Skip to content

SIM401 should catch ternary operations #7288

@jerr0328

Description

@jerr0328

In #4932, there was a bug because if-else blocks were rewritten as ternary operations which SIM401 wouldn't be able to fix. The bug was fixed but there's still the fact that you can have code like

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

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

which will not be corrected with ruff check --fix --select SIM .

Expected behavior:

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

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

Checked with ruff v0.0.287

Metadata

Metadata

Assignees

Labels

acceptedReady for implementationgood first issueGood for newcomershelp wantedContributions especially welcome

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions