---
source: crates/ruff/src/rules/pyflakes/mod.rs
---
F841_3.py:5:5: F841 [*] Local variable `x` is assigned to but never used
  |
5 | def f():
6 |     x = 1
  |     ^ F841
7 |     y = 2
  |
  = help: Remove assignment to unused variable `x`

ℹ Suggested fix
2 2 | 
3 3 | 
4 4 | def f():
5   |-    x = 1
6 5 |     y = 2
7 6 | 
8 7 |     z = 3

F841_3.py:6:5: F841 [*] Local variable `y` is assigned to but never used
   |
 6 | def f():
 7 |     x = 1
 8 |     y = 2
   |     ^ F841
 9 | 
10 |     z = 3
   |
   = help: Remove assignment to unused variable `y`

ℹ Suggested fix
3 3 | 
4 4 | def f():
5 5 |     x = 1
6   |-    y = 2
7 6 | 
8 7 |     z = 3
9 8 |     print(z)

F841_3.py:13:5: F841 [*] Local variable `x` is assigned to but never used
   |
13 | def f():
14 |     x: int = 1
   |     ^ F841
15 |     y: int = 2
   |
   = help: Remove assignment to unused variable `x`

ℹ Suggested fix
10 10 | 
11 11 | 
12 12 | def f():
13    |-    x: int = 1
14 13 |     y: int = 2
15 14 | 
16 15 |     z: int = 3

F841_3.py:14:5: F841 [*] Local variable `y` is assigned to but never used
   |
14 | def f():
15 |     x: int = 1
16 |     y: int = 2
   |     ^ F841
17 | 
18 |     z: int = 3
   |
   = help: Remove assignment to unused variable `y`

ℹ Suggested fix
11 11 | 
12 12 | def f():
13 13 |     x: int = 1
14    |-    y: int = 2
15 14 | 
16 15 |     z: int = 3
17 16 |     print(z)

F841_3.py:21:19: F841 [*] Local variable `x1` is assigned to but never used
   |
21 | def f():
22 |     with foo() as x1:
   |                   ^^ F841
23 |         pass
   |
   = help: Remove assignment to unused variable `x1`

ℹ Suggested fix
18 18 | 
19 19 | 
20 20 | def f():
21    |-    with foo() as x1:
   21 |+    with foo():
22 22 |         pass
23 23 | 
24 24 |     with foo() as (x2, y2):

F841_3.py:27:20: F841 [*] Local variable `x3` is assigned to but never used
   |
27 |         pass
28 | 
29 |     with (foo() as x3, foo() as y3, foo() as z3):
   |                    ^^ F841
30 |         pass
   |
   = help: Remove assignment to unused variable `x3`

ℹ Suggested fix
24 24 |     with foo() as (x2, y2):
25 25 |         pass
26 26 | 
27    |-    with (foo() as x3, foo() as y3, foo() as z3):
   27 |+    with (foo(), foo() as y3, foo() as z3):
28 28 |         pass
29 29 | 
30 30 | 

F841_3.py:27:33: F841 [*] Local variable `y3` is assigned to but never used
   |
27 |         pass
28 | 
29 |     with (foo() as x3, foo() as y3, foo() as z3):
   |                                 ^^ F841
30 |         pass
   |
   = help: Remove assignment to unused variable `y3`

ℹ Suggested fix
24 24 |     with foo() as (x2, y2):
25 25 |         pass
26 26 | 
27    |-    with (foo() as x3, foo() as y3, foo() as z3):
   27 |+    with (foo() as x3, foo(), foo() as z3):
28 28 |         pass
29 29 | 
30 30 | 

F841_3.py:27:46: F841 [*] Local variable `z3` is assigned to but never used
   |
27 |         pass
28 | 
29 |     with (foo() as x3, foo() as y3, foo() as z3):
   |                                              ^^ F841
30 |         pass
   |
   = help: Remove assignment to unused variable `z3`

ℹ Suggested fix
24 24 |     with foo() as (x2, y2):
25 25 |         pass
26 26 | 
27    |-    with (foo() as x3, foo() as y3, foo() as z3):
   27 |+    with (foo() as x3, foo() as y3, foo()):
28 28 |         pass
29 29 | 
30 30 | 

F841_3.py:32:6: F841 [*] Local variable `x1` is assigned to but never used
   |
32 | def f():
33 |     (x1, y1) = (1, 2)
   |      ^^ F841
34 |     (x2, y2) = coords2 = (1, 2)
35 |     coords3 = (x3, y3) = (1, 2)
   |
   = help: Remove assignment to unused variable `x1`

F841_3.py:32:10: F841 [*] Local variable `y1` is assigned to but never used
   |
32 | def f():
33 |     (x1, y1) = (1, 2)
   |          ^^ F841
34 |     (x2, y2) = coords2 = (1, 2)
35 |     coords3 = (x3, y3) = (1, 2)
   |
   = help: Remove assignment to unused variable `y1`

F841_3.py:33:16: F841 [*] Local variable `coords2` is assigned to but never used
   |
33 | def f():
34 |     (x1, y1) = (1, 2)
35 |     (x2, y2) = coords2 = (1, 2)
   |                ^^^^^^^ F841
36 |     coords3 = (x3, y3) = (1, 2)
   |
   = help: Remove assignment to unused variable `coords2`

ℹ Suggested fix
30 30 | 
31 31 | def f():
32 32 |     (x1, y1) = (1, 2)
33    |-    (x2, y2) = coords2 = (1, 2)
   33 |+    (x2, y2) = (1, 2)
34 34 |     coords3 = (x3, y3) = (1, 2)
35 35 | 
36 36 | 

F841_3.py:34:5: F841 [*] Local variable `coords3` is assigned to but never used
   |
34 |     (x1, y1) = (1, 2)
35 |     (x2, y2) = coords2 = (1, 2)
36 |     coords3 = (x3, y3) = (1, 2)
   |     ^^^^^^^ F841
   |
   = help: Remove assignment to unused variable `coords3`

ℹ Suggested fix
31 31 | def f():
32 32 |     (x1, y1) = (1, 2)
33 33 |     (x2, y2) = coords2 = (1, 2)
34    |-    coords3 = (x3, y3) = (1, 2)
   34 |+    (x3, y3) = (1, 2)
35 35 | 
36 36 | 
37 37 | def f():

F841_3.py:40:26: F841 [*] Local variable `x1` is assigned to but never used
   |
40 |     try:
41 |         1 / 0
42 |     except ValueError as x1:
   |                          ^^ F841
43 |         pass
   |
   = help: Remove assignment to unused variable `x1`

ℹ Suggested fix
37 37 | def f():
38 38 |     try:
39 39 |         1 / 0
40    |-    except ValueError as x1:
   40 |+    except ValueError:
41 41 |         pass
42 42 | 
43 43 |     try:

F841_3.py:45:47: F841 [*] Local variable `x2` is assigned to but never used
   |
45 |     try:
46 |         1 / 0
47 |     except (ValueError, ZeroDivisionError) as x2:
   |                                               ^^ F841
48 |         pass
   |
   = help: Remove assignment to unused variable `x2`

ℹ Suggested fix
42 42 | 
43 43 |     try:
44 44 |         1 / 0
45    |-    except (ValueError, ZeroDivisionError) as x2:
   45 |+    except (ValueError, ZeroDivisionError):
46 46 |         pass
47 47 | 
48 48 | 

F841_3.py:50:5: F841 [*] Local variable `x` is assigned to but never used
   |
50 | def f(a, b):
51 |     x = (
   |     ^ F841
52 |         a()
53 |         if a is not None
   |
   = help: Remove assignment to unused variable `x`

ℹ Suggested fix
47 47 | 
48 48 | 
49 49 | def f(a, b):
50    |-    x = (
   50 |+    (
51 51 |         a()
52 52 |         if a is not None
53 53 |         else b

F841_3.py:56:5: F841 [*] Local variable `y` is assigned to but never used
   |
56 |     )
57 | 
58 |     y = \
   |     ^ F841
59 |         a() if a is not None else b
   |
   = help: Remove assignment to unused variable `y`

ℹ Suggested fix
53 53 |         else b
54 54 |     )
55 55 | 
56    |-    y = \
57    |-        a() if a is not None else b
   56 |+    a() if a is not None else b
58 57 | 
59 58 | 
60 59 | def f(a, b):

F841_3.py:61:5: F841 [*] Local variable `x` is assigned to but never used
   |
61 | def f(a, b):
62 |     x = (
   |     ^ F841
63 |         a
64 |         if a is not None
   |
   = help: Remove assignment to unused variable `x`

ℹ Suggested fix
58 58 | 
59 59 | 
60 60 | def f(a, b):
61    |-    x = (
62    |-        a
63    |-        if a is not None
64    |-        else b
65    |-    )
   61 |+    pass
66 62 | 
67 63 |     y = \
68 64 |         a if a is not None else b

F841_3.py:67:5: F841 [*] Local variable `y` is assigned to but never used
   |
67 |     )
68 | 
69 |     y = \
   |     ^ F841
70 |         a if a is not None else b
   |
   = help: Remove assignment to unused variable `y`

ℹ Suggested fix
64 64 |         else b
65 65 |     )
66 66 | 
67    |-    y = \
68    |-        a if a is not None else b
69 67 | 
70 68 | 
71 69 | def f():

F841_3.py:72:24: F841 [*] Local variable `cm` is assigned to but never used
   |
72 | def f():
73 |     with Nested(m) as (cm):
   |                        ^^ F841
74 |         pass
   |
   = help: Remove assignment to unused variable `cm`

ℹ Suggested fix
69 69 | 
70 70 | 
71 71 | def f():
72    |-    with Nested(m) as (cm):
   72 |+    with Nested(m):
73 73 |         pass
74 74 | 
75 75 | 

F841_3.py:77:25: F841 [*] Local variable `cm` is assigned to but never used
   |
77 | def f():
78 |     with (Nested(m) as (cm),):
   |                         ^^ F841
79 |         pass
   |
   = help: Remove assignment to unused variable `cm`

ℹ Suggested fix
74 74 | 
75 75 | 
76 76 | def f():
77    |-    with (Nested(m) as (cm),):
   77 |+    with (Nested(m),):
78 78 |         pass
79 79 | 
80 80 | 

F841_3.py:87:5: F841 [*] Local variable `toplevel` is assigned to but never used
   |
87 | def f():
88 |     toplevel = tt = lexer.get_token()
   |     ^^^^^^^^ F841
89 |     if not tt:
90 |         break
   |
   = help: Remove assignment to unused variable `toplevel`

ℹ Suggested fix
84 84 | 
85 85 | 
86 86 | def f():
87    |-    toplevel = tt = lexer.get_token()
   87 |+    tt = lexer.get_token()
88 88 |     if not tt:
89 89 |         break
90 90 | 

F841_3.py:93:5: F841 [*] Local variable `toplevel` is assigned to but never used
   |
93 | def f():
94 |     toplevel = tt = lexer.get_token()
   |     ^^^^^^^^ F841
   |
   = help: Remove assignment to unused variable `toplevel`

ℹ Suggested fix
90 90 | 
91 91 | 
92 92 | def f():
93    |-    toplevel = tt = lexer.get_token()
   93 |+    tt = lexer.get_token()
94 94 | 
95 95 | 
96 96 | def f():

F841_3.py:93:16: F841 [*] Local variable `tt` is assigned to but never used
   |
93 | def f():
94 |     toplevel = tt = lexer.get_token()
   |                ^^ F841
   |
   = help: Remove assignment to unused variable `tt`

ℹ Suggested fix
90 90 | 
91 91 | 
92 92 | def f():
93    |-    toplevel = tt = lexer.get_token()
   93 |+    toplevel = lexer.get_token()
94 94 | 
95 95 | 
96 96 | def f():

F841_3.py:97:5: F841 [*] Local variable `toplevel` is assigned to but never used
   |
97 | def f():
98 |     toplevel = (a, b) = lexer.get_token()
   |     ^^^^^^^^ F841
   |
   = help: Remove assignment to unused variable `toplevel`

ℹ Suggested fix
94 94 | 
95 95 | 
96 96 | def f():
97    |-    toplevel = (a, b) = lexer.get_token()
   97 |+    (a, b) = lexer.get_token()
98 98 | 
99 99 | 
100 100 | def f():

F841_3.py:101:14: F841 [*] Local variable `toplevel` is assigned to but never used
    |
101 | def f():
102 |     (a, b) = toplevel = lexer.get_token()
    |              ^^^^^^^^ F841
    |
    = help: Remove assignment to unused variable `toplevel`

ℹ Suggested fix
98  98  | 
99  99  | 
100 100 | def f():
101     |-    (a, b) = toplevel = lexer.get_token()
    101 |+    (a, b) = lexer.get_token()
102 102 | 
103 103 | 
104 104 | def f():

F841_3.py:105:5: F841 [*] Local variable `toplevel` is assigned to but never used
    |
105 | def f():
106 |     toplevel = tt = 1
    |     ^^^^^^^^ F841
    |
    = help: Remove assignment to unused variable `toplevel`

ℹ Suggested fix
102 102 | 
103 103 | 
104 104 | def f():
105     |-    toplevel = tt = 1
    105 |+    tt = 1

F841_3.py:105:16: F841 [*] Local variable `tt` is assigned to but never used
    |
105 | def f():
106 |     toplevel = tt = 1
    |                ^^ F841
    |
    = help: Remove assignment to unused variable `tt`

ℹ Suggested fix
102 102 | 
103 103 | 
104 104 | def f():
105     |-    toplevel = tt = 1
    105 |+    toplevel = 1


