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

RUF015 bad code example does not throw a warning #5764

Closed
jschippergoauto opened this issue Jul 14, 2023 · 0 comments · Fixed by #5767
Closed

RUF015 bad code example does not throw a warning #5764

jschippergoauto opened this issue Jul 14, 2023 · 0 comments · Fixed by #5767
Assignees
Labels
bug Something isn't working

Comments

@jschippergoauto
Copy link

Ruff version: 0.0.278
Command: ruff --config=ruff.toml file.py
ruff.toml:

extend-select = [
  "RUF",
]

Code snippet:

head = list(range(1000000000000))[0]

The code snippet was taken from the Ruff documentation

I expected it to give me a RUF015 warning but instead it completely ignores it. Changing the snippet to the following does throw a warning.

x = range(1000000000000)
head = list(x)[0]
@charliermarsh charliermarsh added the bug Something isn't working label Jul 14, 2023
@charliermarsh charliermarsh self-assigned this Jul 14, 2023
charliermarsh added a commit that referenced this issue Jul 21, 2023
## Summary

We now allow RUF015 to fix cases like:

```python
list(range(10))[0]
list(x.y)[0]
list(x["y"])[0]
```

Further, we fix generators like:

```python
[i + 1 for i in x][0]
```

By rewriting to `next(iter(i + 1 for i in x))`.

I've retained the special-case that rewrites `[i for i in x][0]` to
`next(iter(x))`.

Closes #5764.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants