Ideas for new lints around iteration
- Dominant language
- Rust
- Stars
- 49.7k
- Forks
- 2.4k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 458
Description
I apologize if you not looking for new lints to implement in Ruff.
I do a fair share of code reviews, and I quite often stumble on these issues which are not caught by any linter AFAICT (flake8, pylint, refurb, ruff). I am not sure how hard those would be to implement, as for the first one you would need some type inference.
```python
a = [1, 2]
b = [3, 4]
# Not good
for x in a + b:
print(x)
# Better but not really good either
for x in *a, *b:
print(x)
# Best
for x in itertools.chain(a, b):
print(x)
```
This happens really often when people want to iterate on multiple lists, tuples, etc.
Another one in a similar spirit:
```python
a = [1, 2]
b = [3, 4]
c = [a, b]
# Not good
for x in itertools.chain(*c):
print(x)
# Better
for x in itertools.chain.from_iterable(c):
print(x)
```
Contributor guide
Research direction
No files, tests, or entry points are named. Start by reviewing Ruff's existing lint rules and how it represents Python iteration, then determine whether these two proposed patterns have precise, implementable semantics. Done means the lint scope and expected diagnostics are agreed before implementation begins.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100