ruff
134d447d - Avoid refactoring `x[:1]`-like slices in RUF015 (#6150)

Commit
2 years ago
Avoid refactoring `x[:1]`-like slices in RUF015 (#6150) ## Summary Right now, `RUF015` will try to rewrite `x[:1]` as `[next(x)]`. This isn't equivalent if `x`, for example, is empty, where slicing like `x[:1]` is forgiving, but `next` raises `StopIteration`. For me this is a little too much of a deviation to be comfortable with, and most of the value in this rule is the `x[0]` to `next(x)` conversion anyway. Closes https://github.com/astral-sh/ruff/issues/6148.
Author
Parents
Loading