---
source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs
---
C413 [*] Unnecessary `list()` call around `sorted()`
 --> C413.py:3:1
  |
1 | x = [2, 3, 1]
2 | list(x)
3 | list(sorted(x))
  | ^^^^^^^^^^^^^^^
4 | reversed(sorted(x))
5 | reversed(sorted(x, key=lambda e: e))
  |
help: Remove unnecessary `list()` call
  |
2 | list(x)
  - list(sorted(x))
3 + sorted(x)
4 | reversed(sorted(x))
  |

C413 [*] Unnecessary `reversed()` call around `sorted()`
 --> C413.py:4:1
  |
2 | list(x)
3 | list(sorted(x))
4 | reversed(sorted(x))
  | ^^^^^^^^^^^^^^^^^^^
5 | reversed(sorted(x, key=lambda e: e))
6 | reversed(sorted(x, reverse=True))
  |
help: Remove unnecessary `reversed()` call
  |
3 | list(sorted(x))
  - reversed(sorted(x))
4 + sorted(x, reverse=True)
5 | reversed(sorted(x, key=lambda e: e))
  |
note: This is an unsafe fix and may change runtime behavior

C413 [*] Unnecessary `reversed()` call around `sorted()`
 --> C413.py:5:1
  |
3 | list(sorted(x))
4 | reversed(sorted(x))
5 | reversed(sorted(x, key=lambda e: e))
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6 | reversed(sorted(x, reverse=True))
7 | reversed(sorted(x, key=lambda e: e, reverse=True))
  |
help: Remove unnecessary `reversed()` call
  |
4 | reversed(sorted(x))
  - reversed(sorted(x, key=lambda e: e))
5 + sorted(x, key=lambda e: e, reverse=True)
6 | reversed(sorted(x, reverse=True))
  |
note: This is an unsafe fix and may change runtime behavior

C413 [*] Unnecessary `reversed()` call around `sorted()`
 --> C413.py:6:1
  |
4 | reversed(sorted(x))
5 | reversed(sorted(x, key=lambda e: e))
6 | reversed(sorted(x, reverse=True))
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7 | reversed(sorted(x, key=lambda e: e, reverse=True))
8 | reversed(sorted(x, reverse=True, key=lambda e: e))
  |
help: Remove unnecessary `reversed()` call
  |
5 | reversed(sorted(x, key=lambda e: e))
  - reversed(sorted(x, reverse=True))
6 + sorted(x, reverse=False)
7 | reversed(sorted(x, key=lambda e: e, reverse=True))
  |
note: This is an unsafe fix and may change runtime behavior

C413 [*] Unnecessary `reversed()` call around `sorted()`
 --> C413.py:7:1
  |
5 | reversed(sorted(x, key=lambda e: e))
6 | reversed(sorted(x, reverse=True))
7 | reversed(sorted(x, key=lambda e: e, reverse=True))
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8 | reversed(sorted(x, reverse=True, key=lambda e: e))
9 | reversed(sorted(x, reverse=False))
  |
help: Remove unnecessary `reversed()` call
  |
6 | reversed(sorted(x, reverse=True))
  - reversed(sorted(x, key=lambda e: e, reverse=True))
7 + sorted(x, key=lambda e: e, reverse=False)
8 | reversed(sorted(x, reverse=True, key=lambda e: e))
  |
note: This is an unsafe fix and may change runtime behavior

C413 [*] Unnecessary `reversed()` call around `sorted()`
  --> C413.py:8:1
   |
 6 | reversed(sorted(x, reverse=True))
 7 | reversed(sorted(x, key=lambda e: e, reverse=True))
 8 | reversed(sorted(x, reverse=True, key=lambda e: e))
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 9 | reversed(sorted(x, reverse=False))
10 | reversed(sorted(x, reverse=x))
   |
help: Remove unnecessary `reversed()` call
  |
7 | reversed(sorted(x, key=lambda e: e, reverse=True))
  - reversed(sorted(x, reverse=True, key=lambda e: e))
8 + sorted(x, reverse=False, key=lambda e: e)
9 | reversed(sorted(x, reverse=False))
  |
note: This is an unsafe fix and may change runtime behavior

C413 [*] Unnecessary `reversed()` call around `sorted()`
  --> C413.py:9:1
   |
 7 | reversed(sorted(x, key=lambda e: e, reverse=True))
 8 | reversed(sorted(x, reverse=True, key=lambda e: e))
 9 | reversed(sorted(x, reverse=False))
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10 | reversed(sorted(x, reverse=x))
11 | reversed(sorted(x, reverse=not x))
   |
help: Remove unnecessary `reversed()` call
   |
8  | reversed(sorted(x, reverse=True, key=lambda e: e))
   - reversed(sorted(x, reverse=False))
9  + sorted(x, reverse=True)
10 | reversed(sorted(x, reverse=x))
   |
note: This is an unsafe fix and may change runtime behavior

C413 [*] Unnecessary `reversed()` call around `sorted()`
  --> C413.py:10:1
   |
 8 | reversed(sorted(x, reverse=True, key=lambda e: e))
 9 | reversed(sorted(x, reverse=False))
10 | reversed(sorted(x, reverse=x))
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11 | reversed(sorted(x, reverse=not x))
   |
help: Remove unnecessary `reversed()` call
   |
9  | reversed(sorted(x, reverse=False))
   - reversed(sorted(x, reverse=x))
10 + sorted(x, reverse=not x)
11 | reversed(sorted(x, reverse=not x))
   |
note: This is an unsafe fix and may change runtime behavior

C413 [*] Unnecessary `reversed()` call around `sorted()`
  --> C413.py:11:1
   |
 9 | reversed(sorted(x, reverse=False))
10 | reversed(sorted(x, reverse=x))
11 | reversed(sorted(x, reverse=not x))
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12 |
13 | # Regression test for: https://github.com/astral-sh/ruff/issues/7289
   |
help: Remove unnecessary `reversed()` call
   |
10 | reversed(sorted(x, reverse=x))
   - reversed(sorted(x, reverse=not x))
11 + sorted(x, reverse=x)
12 |
   |
note: This is an unsafe fix and may change runtime behavior

C413 [*] Unnecessary `reversed()` call around `sorted()`
  --> C413.py:14:1
   |
13 | # Regression test for: https://github.com/astral-sh/ruff/issues/7289
14 | reversed(sorted(i for i in range(42)))
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15 | reversed(sorted((i for i in range(42)), reverse=True))
   |
help: Remove unnecessary `reversed()` call
   |
13 | # Regression test for: https://github.com/astral-sh/ruff/issues/7289
   - reversed(sorted(i for i in range(42)))
14 + sorted((i for i in range(42)), reverse=True)
15 | reversed(sorted((i for i in range(42)), reverse=True))
   |
note: This is an unsafe fix and may change runtime behavior

C413 [*] Unnecessary `reversed()` call around `sorted()`
  --> C413.py:15:1
   |
13 | # Regression test for: https://github.com/astral-sh/ruff/issues/7289
14 | reversed(sorted(i for i in range(42)))
15 | reversed(sorted((i for i in range(42)), reverse=True))
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16 |
17 | # Regression test for: https://github.com/astral-sh/ruff/issues/10335
   |
help: Remove unnecessary `reversed()` call
   |
14 | reversed(sorted(i for i in range(42)))
   - reversed(sorted((i for i in range(42)), reverse=True))
15 + sorted((i for i in range(42)), reverse=False)
16 |
   |
note: This is an unsafe fix and may change runtime behavior

C413 [*] Unnecessary `reversed()` call around `sorted()`
  --> C413.py:18:1
   |
17 | # Regression test for: https://github.com/astral-sh/ruff/issues/10335
18 | reversed(sorted([1, 2, 3], reverse=False or True))
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19 | reversed(sorted([1, 2, 3], reverse=(False or True)))
   |
help: Remove unnecessary `reversed()` call
   |
17 | # Regression test for: https://github.com/astral-sh/ruff/issues/10335
   - reversed(sorted([1, 2, 3], reverse=False or True))
18 + sorted([1, 2, 3], reverse=not (False or True))
19 | reversed(sorted([1, 2, 3], reverse=(False or True)))
   |
note: This is an unsafe fix and may change runtime behavior

C413 [*] Unnecessary `reversed()` call around `sorted()`
  --> C413.py:19:1
   |
17 | # Regression test for: https://github.com/astral-sh/ruff/issues/10335
18 | reversed(sorted([1, 2, 3], reverse=False or True))
19 | reversed(sorted([1, 2, 3], reverse=(False or True)))
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20 |
21 | # These fixes need to be parenthesized to avoid syntax errors and behavior
   |
help: Remove unnecessary `reversed()` call
   |
18 | reversed(sorted([1, 2, 3], reverse=False or True))
   - reversed(sorted([1, 2, 3], reverse=(False or True)))
19 + sorted([1, 2, 3], reverse=not (False or True))
20 |
   |
note: This is an unsafe fix and may change runtime behavior

C413 [*] Unnecessary `reversed()` call around `sorted()`
  --> C413.py:24:1
   |
22 |   # changes.
23 |   # See https://github.com/astral-sh/ruff/issues/15789
24 | / reversed(sorted
25 | | (""))
   | |_____^
26 |   list(sorted
27 |       (""))
   |
help: Remove unnecessary `reversed()` call
   |
23 | # See https://github.com/astral-sh/ruff/issues/15789
   - reversed(sorted
   - (""))
24 + (sorted
25 + ("", reverse=True))
26 | list(sorted
   |
note: This is an unsafe fix and may change runtime behavior

C413 [*] Unnecessary `list()` call around `sorted()`
  --> C413.py:26:1
   |
24 |   reversed(sorted
25 |   (""))
26 | / list(sorted
27 | |     (""))
   | |_________^
28 |   list(sorted
29 |   ("xy"))
   |
help: Remove unnecessary `list()` call
   |
25 | (""))
   - list(sorted
26 + (sorted
27 |     (""))
   |

C413 [*] Unnecessary `list()` call around `sorted()`
  --> C413.py:28:1
   |
26 |   list(sorted
27 |       (""))
28 | / list(sorted
29 | | ("xy"))
   | |_______^
   |
help: Remove unnecessary `list()` call
   |
27 |     (""))
   - list(sorted
28 + (sorted
29 | ("xy"))
   |
