astral-sh / astral-sh/ruff

Expand SIM118 to cover AnySequence(dict.keys())

Open
#4,262 5 comments 2 reactions 0 assignees View on GitHub
needs-decision rule
Dominant language
Rust
Stars
49.6k
Forks
2.4k
Avg merge
2d 1h
Merged PRs (30d)
458

Description

Would be nice if SIM118 could be expanded (or a new rule created) that not just covers iterating over dict keys but also converting them to any type of iterable:

```py
# bad
list(dict.keys())
tuple(dict.keys())
set(dict.keys())
[*dict.keys()]
{*dict.keys()}

# good
list(dict)
tuple(dict)
set(dict)
[*dict]
{*dict}
```

Contributor guide

Open the contributing guide

Research direction

Start by locating the SIM118 rule and its tests in the Ruff codebase. Compare the existing dict-key iteration cases with the listed list, tuple, set, and unpacking examples. Done means the rule consistently recognizes those conversions and the tests cover the bad and good forms.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.