mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:18 +00:00
[flake8-comprehensions
] bugfix for C413 autofix (#2804)
This commit is contained in:
parent
f8ac6d7bf0
commit
2dccb7611a
6 changed files with 156 additions and 5 deletions
29
docs/rules/unnecessary-call-around-sorted.md
Normal file
29
docs/rules/unnecessary-call-around-sorted.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
# unnecessary-call-around-sorted (C413)
|
||||
|
||||
Derived from the **flake8-comprehensions** linter.
|
||||
|
||||
Autofix is always available.
|
||||
|
||||
## What it does
|
||||
Checks for unnecessary `list` or `reversed` calls around `sorted`
|
||||
calls.
|
||||
|
||||
## Why is this bad?
|
||||
It is unnecessary to use `list` around `sorted`, as the latter already
|
||||
returns a list.
|
||||
|
||||
It is also unnecessary to use `reversed` around `sorted`, as the latter
|
||||
has a `reverse` argument that can be used in lieu of an additional
|
||||
`reversed` call.
|
||||
|
||||
In both cases, it's clearer to avoid the redundant call.
|
||||
|
||||
## Examples
|
||||
```python
|
||||
reversed(sorted(iterable))
|
||||
```
|
||||
|
||||
Use instead:
|
||||
```python
|
||||
sorted(iterable, reverse=True)
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue