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

ℹ Safe fix
1 1 | x = [2, 3, 1]
2 2 | list(x)
3   |-list(sorted(x))
  3 |+sorted(x)
4 4 | reversed(sorted(x))
5 5 | reversed(sorted(x, key=lambda e: e))
6 6 | reversed(sorted(x, reverse=True))

C413.py:4:1: C413 [*] Unnecessary `reversed` call around `sorted()`
  |
2 | list(x)
3 | list(sorted(x))
4 | reversed(sorted(x))
  | ^^^^^^^^^^^^^^^^^^^ C413
5 | reversed(sorted(x, key=lambda e: e))
6 | reversed(sorted(x, reverse=True))
  |
  = help: Remove unnecessary `reversed` call

ℹ Unsafe fix
1 1 | x = [2, 3, 1]
2 2 | list(x)
3 3 | list(sorted(x))
4   |-reversed(sorted(x))
  4 |+sorted(x, reverse=True)
5 5 | reversed(sorted(x, key=lambda e: e))
6 6 | reversed(sorted(x, reverse=True))
7 7 | reversed(sorted(x, key=lambda e: e, reverse=True))

C413.py:5:1: C413 [*] Unnecessary `reversed` call around `sorted()`
  |
3 | list(sorted(x))
4 | reversed(sorted(x))
5 | reversed(sorted(x, key=lambda e: e))
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413
6 | reversed(sorted(x, reverse=True))
7 | reversed(sorted(x, key=lambda e: e, reverse=True))
  |
  = help: Remove unnecessary `reversed` call

ℹ Unsafe fix
2 2 | list(x)
3 3 | list(sorted(x))
4 4 | reversed(sorted(x))
5   |-reversed(sorted(x, key=lambda e: e))
  5 |+sorted(x, key=lambda e: e, reverse=True)
6 6 | reversed(sorted(x, reverse=True))
7 7 | reversed(sorted(x, key=lambda e: e, reverse=True))
8 8 | reversed(sorted(x, reverse=True, key=lambda e: e))

C413.py:6:1: C413 [*] Unnecessary `reversed` call around `sorted()`
  |
4 | reversed(sorted(x))
5 | reversed(sorted(x, key=lambda e: e))
6 | reversed(sorted(x, reverse=True))
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413
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

ℹ Unsafe fix
3 3 | list(sorted(x))
4 4 | reversed(sorted(x))
5 5 | reversed(sorted(x, key=lambda e: e))
6   |-reversed(sorted(x, reverse=True))
  6 |+sorted(x, reverse=False)
7 7 | reversed(sorted(x, key=lambda e: e, reverse=True))
8 8 | reversed(sorted(x, reverse=True, key=lambda e: e))
9 9 | reversed(sorted(x, reverse=False))

C413.py:7:1: C413 [*] Unnecessary `reversed` call around `sorted()`
  |
5 | reversed(sorted(x, key=lambda e: e))
6 | reversed(sorted(x, reverse=True))
7 | reversed(sorted(x, key=lambda e: e, reverse=True))
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413
8 | reversed(sorted(x, reverse=True, key=lambda e: e))
9 | reversed(sorted(x, reverse=False))
  |
  = help: Remove unnecessary `reversed` call

ℹ Unsafe fix
4 4 | reversed(sorted(x))
5 5 | reversed(sorted(x, key=lambda e: e))
6 6 | reversed(sorted(x, reverse=True))
7   |-reversed(sorted(x, key=lambda e: e, reverse=True))
  7 |+sorted(x, key=lambda e: e, reverse=False)
8 8 | reversed(sorted(x, reverse=True, key=lambda e: e))
9 9 | reversed(sorted(x, reverse=False))
10 10 | reversed(sorted(x, reverse=x))

C413.py:8:1: C413 [*] Unnecessary `reversed` call around `sorted()`
   |
 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))
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413
 9 | reversed(sorted(x, reverse=False))
10 | reversed(sorted(x, reverse=x))
   |
   = help: Remove unnecessary `reversed` call

ℹ Unsafe fix
5 5 | reversed(sorted(x, key=lambda e: e))
6 6 | reversed(sorted(x, reverse=True))
7 7 | reversed(sorted(x, key=lambda e: e, reverse=True))
8   |-reversed(sorted(x, reverse=True, key=lambda e: e))
  8 |+sorted(x, reverse=False, key=lambda e: e)
9 9 | reversed(sorted(x, reverse=False))
10 10 | reversed(sorted(x, reverse=x))
11 11 | reversed(sorted(x, reverse=not x))

C413.py:9:1: C413 [*] Unnecessary `reversed` call around `sorted()`
   |
 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))
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413
10 | reversed(sorted(x, reverse=x))
11 | reversed(sorted(x, reverse=not x))
   |
   = help: Remove unnecessary `reversed` call

ℹ Unsafe fix
6  6  | reversed(sorted(x, reverse=True))
7  7  | reversed(sorted(x, key=lambda e: e, reverse=True))
8  8  | reversed(sorted(x, reverse=True, key=lambda e: e))
9     |-reversed(sorted(x, reverse=False))
   9  |+sorted(x, reverse=True)
10 10 | reversed(sorted(x, reverse=x))
11 11 | reversed(sorted(x, reverse=not x))
12 12 | 

C413.py:10:1: C413 [*] Unnecessary `reversed` call around `sorted()`
   |
 8 | reversed(sorted(x, reverse=True, key=lambda e: e))
 9 | reversed(sorted(x, reverse=False))
10 | reversed(sorted(x, reverse=x))
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413
11 | reversed(sorted(x, reverse=not x))
   |
   = help: Remove unnecessary `reversed` call

ℹ Unsafe fix
7  7  | reversed(sorted(x, key=lambda e: e, reverse=True))
8  8  | reversed(sorted(x, reverse=True, key=lambda e: e))
9  9  | reversed(sorted(x, reverse=False))
10    |-reversed(sorted(x, reverse=x))
   10 |+sorted(x, reverse=not x)
11 11 | reversed(sorted(x, reverse=not x))
12 12 | 
13 13 | # Regression test for: https://github.com/astral-sh/ruff/issues/7289

C413.py:11:1: C413 [*] Unnecessary `reversed` call around `sorted()`
   |
 9 | reversed(sorted(x, reverse=False))
10 | reversed(sorted(x, reverse=x))
11 | reversed(sorted(x, reverse=not x))
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413
12 | 
13 | # Regression test for: https://github.com/astral-sh/ruff/issues/7289
   |
   = help: Remove unnecessary `reversed` call

ℹ Unsafe fix
8  8  | reversed(sorted(x, reverse=True, key=lambda e: e))
9  9  | reversed(sorted(x, reverse=False))
10 10 | reversed(sorted(x, reverse=x))
11    |-reversed(sorted(x, reverse=not x))
   11 |+sorted(x, reverse=x)
12 12 | 
13 13 | # Regression test for: https://github.com/astral-sh/ruff/issues/7289
14 14 | reversed(sorted(i for i in range(42)))

C413.py:14:1: C413 [*] Unnecessary `reversed` call around `sorted()`
   |
13 | # Regression test for: https://github.com/astral-sh/ruff/issues/7289
14 | reversed(sorted(i for i in range(42)))
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413
15 | reversed(sorted((i for i in range(42)), reverse=True))
   |
   = help: Remove unnecessary `reversed` call

ℹ Unsafe fix
11 11 | reversed(sorted(x, reverse=not x))
12 12 | 
13 13 | # Regression test for: https://github.com/astral-sh/ruff/issues/7289
14    |-reversed(sorted(i for i in range(42)))
   14 |+sorted((i for i in range(42)), reverse=True)
15 15 | reversed(sorted((i for i in range(42)), reverse=True))
16 16 | 
17 17 | # Regression test for: https://github.com/astral-sh/ruff/issues/10335

C413.py:15:1: C413 [*] Unnecessary `reversed` call around `sorted()`
   |
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))
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413
16 | 
17 | # Regression test for: https://github.com/astral-sh/ruff/issues/10335
   |
   = help: Remove unnecessary `reversed` call

ℹ Unsafe fix
12 12 | 
13 13 | # Regression test for: https://github.com/astral-sh/ruff/issues/7289
14 14 | reversed(sorted(i for i in range(42)))
15    |-reversed(sorted((i for i in range(42)), reverse=True))
   15 |+sorted((i for i in range(42)), reverse=False)
16 16 | 
17 17 | # Regression test for: https://github.com/astral-sh/ruff/issues/10335
18 18 | reversed(sorted([1, 2, 3], reverse=False or True))

C413.py:18:1: C413 [*] Unnecessary `reversed` call around `sorted()`
   |
17 | # Regression test for: https://github.com/astral-sh/ruff/issues/10335
18 | reversed(sorted([1, 2, 3], reverse=False or True))
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413
19 | reversed(sorted([1, 2, 3], reverse=(False or True)))
   |
   = help: Remove unnecessary `reversed` call

ℹ Unsafe fix
15 15 | reversed(sorted((i for i in range(42)), reverse=True))
16 16 | 
17 17 | # Regression test for: https://github.com/astral-sh/ruff/issues/10335
18    |-reversed(sorted([1, 2, 3], reverse=False or True))
   18 |+sorted([1, 2, 3], reverse=not (False or True))
19 19 | reversed(sorted([1, 2, 3], reverse=(False or True)))

C413.py:19:1: C413 [*] Unnecessary `reversed` call around `sorted()`
   |
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)))
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413
   |
   = help: Remove unnecessary `reversed` call

ℹ Unsafe fix
16 16 | 
17 17 | # Regression test for: https://github.com/astral-sh/ruff/issues/10335
18 18 | reversed(sorted([1, 2, 3], reverse=False or True))
19    |-reversed(sorted([1, 2, 3], reverse=(False or True)))
   19 |+sorted([1, 2, 3], reverse=not (False or True))
