---
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
---
F841 [*] Local variable `x` is assigned to but never used
 --> F841_3.py:5:5
  |
4 | def f():
5 |     x = 1
  |     ^
6 |     y = 2
  |
help: Remove assignment to unused variable `x`
  |
4 | def f():
  -     x = 1
5 |     y = 2
  |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `y` is assigned to but never used
 --> F841_3.py:6:5
  |
4 | def f():
5 |     x = 1
6 |     y = 2
  |     ^
7 |
8 |     z = 3
  |
help: Remove assignment to unused variable `y`
  |
5 |     x = 1
  -     y = 2
6 |
  |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `x` is assigned to but never used
  --> F841_3.py:13:5
   |
12 | def f():
13 |     x: int = 1
   |     ^
14 |     y: int = 2
   |
help: Remove assignment to unused variable `x`
   |
12 | def f():
   -     x: int = 1
13 |     y: int = 2
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `y` is assigned to but never used
  --> F841_3.py:14:5
   |
12 | def f():
13 |     x: int = 1
14 |     y: int = 2
   |     ^
15 |
16 |     z: int = 3
   |
help: Remove assignment to unused variable `y`
   |
13 |     x: int = 1
   -     y: int = 2
14 |
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `x1` is assigned to but never used
  --> F841_3.py:21:19
   |
20 | def f():
21 |     with foo() as x1:
   |                   ^^
22 |         pass
   |
help: Remove assignment to unused variable `x1`
   |
20 | def f():
   -     with foo() as x1:
21 +     with foo():
22 |         pass
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `x3` is assigned to but never used
  --> F841_3.py:27:20
   |
25 |         pass
26 |
27 |     with (foo() as x3, foo() as y3, foo() as z3):
   |                    ^^
28 |         pass
   |
help: Remove assignment to unused variable `x3`
   |
26 |
   -     with (foo() as x3, foo() as y3, foo() as z3):
27 +     with (foo(), foo() as y3, foo() as z3):
28 |         pass
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `y3` is assigned to but never used
  --> F841_3.py:27:33
   |
25 |         pass
26 |
27 |     with (foo() as x3, foo() as y3, foo() as z3):
   |                                 ^^
28 |         pass
   |
help: Remove assignment to unused variable `y3`
   |
26 |
   -     with (foo() as x3, foo() as y3, foo() as z3):
27 +     with (foo() as x3, foo(), foo() as z3):
28 |         pass
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `z3` is assigned to but never used
  --> F841_3.py:27:46
   |
25 |         pass
26 |
27 |     with (foo() as x3, foo() as y3, foo() as z3):
   |                                              ^^
28 |         pass
   |
help: Remove assignment to unused variable `z3`
   |
26 |
   -     with (foo() as x3, foo() as y3, foo() as z3):
27 +     with (foo() as x3, foo() as y3, foo()):
28 |         pass
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `x1` is assigned to but never used
  --> F841_3.py:32:6
   |
31 | def f():
32 |     (x1, y1) = (1, 2)
   |      ^^
33 |     (x2, y2) = coords2 = (1, 2)
34 |     coords3 = (x3, y3) = (1, 2)
   |
help: Remove assignment to unused variable `x1`
   |
31 | def f():
   -     (x1, y1) = (1, 2)
32 +     (_x1, y1) = (1, 2)
33 |     (x2, y2) = coords2 = (1, 2)
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `y1` is assigned to but never used
  --> F841_3.py:32:10
   |
31 | def f():
32 |     (x1, y1) = (1, 2)
   |          ^^
33 |     (x2, y2) = coords2 = (1, 2)
34 |     coords3 = (x3, y3) = (1, 2)
   |
help: Remove assignment to unused variable `y1`
   |
31 | def f():
   -     (x1, y1) = (1, 2)
32 +     (x1, _y1) = (1, 2)
33 |     (x2, y2) = coords2 = (1, 2)
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `coords2` is assigned to but never used
  --> F841_3.py:33:16
   |
31 | def f():
32 |     (x1, y1) = (1, 2)
33 |     (x2, y2) = coords2 = (1, 2)
   |                ^^^^^^^
34 |     coords3 = (x3, y3) = (1, 2)
   |
help: Remove assignment to unused variable `coords2`
   |
32 |     (x1, y1) = (1, 2)
   -     (x2, y2) = coords2 = (1, 2)
33 +     (x2, y2) = (1, 2)
34 |     coords3 = (x3, y3) = (1, 2)
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `coords3` is assigned to but never used
  --> F841_3.py:34:5
   |
32 |     (x1, y1) = (1, 2)
33 |     (x2, y2) = coords2 = (1, 2)
34 |     coords3 = (x3, y3) = (1, 2)
   |     ^^^^^^^
   |
help: Remove assignment to unused variable `coords3`
   |
33 |     (x2, y2) = coords2 = (1, 2)
   -     coords3 = (x3, y3) = (1, 2)
34 +     (x3, y3) = (1, 2)
35 |
   |
note: This is an unsafe fix and may change runtime behavior

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

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

F841 [*] Local variable `x` is assigned to but never used
  --> F841_3.py:50:5
   |
49 | def f(a, b):
50 |     x = (
   |     ^
51 |         a()
52 |         if a is not None
   |
help: Remove assignment to unused variable `x`
   |
49 | def f(a, b):
   -     x = (
50 +     (
51 |         a()
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `y` is assigned to but never used
  --> F841_3.py:56:5
   |
54 |     )
55 |
56 |     y = \
   |     ^
57 |         a() if a is not None else b
   |
help: Remove assignment to unused variable `y`
   |
55 |
   -     y = \
   -         a() if a is not None else b
56 +     a() if a is not None else b
57 |
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `x` is assigned to but never used
  --> F841_3.py:61:5
   |
60 | def f(a, b):
61 |     x = (
   |     ^
62 |         a
63 |         if a is not None
   |
help: Remove assignment to unused variable `x`
   |
60 | def f(a, b):
   -     x = (
   -         a
   -         if a is not None
   -         else b
   -     )
61 |
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `y` is assigned to but never used
  --> F841_3.py:67:5
   |
65 |     )
66 |
67 |     y = \
   |     ^
68 |         a if a is not None else b
   |
help: Remove assignment to unused variable `y`
   |
66 |
   -     y = \
   -         a if a is not None else b
67 |
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `cm` is assigned to but never used
  --> F841_3.py:72:24
   |
71 | def f():
72 |     with Nested(m) as (cm):
   |                        ^^
73 |         pass
   |
help: Remove assignment to unused variable `cm`
   |
71 | def f():
   -     with Nested(m) as (cm):
72 +     with Nested(m):
73 |         pass
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `cm` is assigned to but never used
  --> F841_3.py:77:25
   |
76 | def f():
77 |     with (Nested(m) as (cm),):
   |                         ^^
78 |         pass
   |
help: Remove assignment to unused variable `cm`
   |
76 | def f():
   -     with (Nested(m) as (cm),):
77 +     with (Nested(m),):
78 |         pass
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `cm` is assigned to but never used
  --> F841_3.py:87:26
   |
86 | def f():
87 |     with (Nested(m)) as (cm):
   |                          ^^
88 |         pass
   |
help: Remove assignment to unused variable `cm`
   |
86 | def f():
   -     with (Nested(m)) as (cm):
87 +     with (Nested(m)):
88 |         pass
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `toplevel` is assigned to but never used
  --> F841_3.py:92:5
   |
91 | def f():
92 |     toplevel = tt = lexer.get_token()
   |     ^^^^^^^^
93 |     if not tt:
94 |         break
   |
help: Remove assignment to unused variable `toplevel`
   |
91 | def f():
   -     toplevel = tt = lexer.get_token()
92 +     tt = lexer.get_token()
93 |     if not tt:
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `toplevel` is assigned to but never used
  --> F841_3.py:98:5
   |
97 | def f():
98 |     toplevel = tt = lexer.get_token()
   |     ^^^^^^^^
   |
help: Remove assignment to unused variable `toplevel`
   |
97 | def f():
   -     toplevel = tt = lexer.get_token()
98 +     tt = lexer.get_token()
99 |
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `tt` is assigned to but never used
  --> F841_3.py:98:16
   |
97 | def f():
98 |     toplevel = tt = lexer.get_token()
   |                ^^
   |
help: Remove assignment to unused variable `tt`
   |
97 | def f():
   -     toplevel = tt = lexer.get_token()
98 +     toplevel = lexer.get_token()
99 |
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `toplevel` is assigned to but never used
   --> F841_3.py:102:5
    |
101 | def f():
102 |     toplevel = (a, b) = lexer.get_token()
    |     ^^^^^^^^
    |
help: Remove assignment to unused variable `toplevel`
    |
101 | def f():
    -     toplevel = (a, b) = lexer.get_token()
102 +     (a, b) = lexer.get_token()
103 |
    |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `toplevel` is assigned to but never used
   --> F841_3.py:106:14
    |
105 | def f():
106 |     (a, b) = toplevel = lexer.get_token()
    |              ^^^^^^^^
    |
help: Remove assignment to unused variable `toplevel`
    |
105 | def f():
    -     (a, b) = toplevel = lexer.get_token()
106 +     (a, b) = lexer.get_token()
107 |
    |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `toplevel` is assigned to but never used
   --> F841_3.py:110:5
    |
109 | def f():
110 |     toplevel = tt = 1
    |     ^^^^^^^^
    |
help: Remove assignment to unused variable `toplevel`
    |
109 | def f():
    -     toplevel = tt = 1
110 +     tt = 1
111 |
    |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `tt` is assigned to but never used
   --> F841_3.py:110:16
    |
109 | def f():
110 |     toplevel = tt = 1
    |                ^^
    |
help: Remove assignment to unused variable `tt`
    |
109 | def f():
    -     toplevel = tt = 1
110 +     toplevel = 1
111 |
    |
note: This is an unsafe fix and may change runtime behavior

F841 Local variable `x` is assigned to but never used
   --> F841_3.py:115:19
    |
113 | def f(provided: int) -> int:
114 |     match provided:
115 |         case [_, *x]:
    |                   ^
116 |             pass
    |
help: Remove assignment to unused variable `x`

F841 Local variable `x` is assigned to but never used
   --> F841_3.py:121:14
    |
119 | def f(provided: int) -> int:
120 |     match provided:
121 |         case x:
    |              ^
122 |             pass
    |
help: Remove assignment to unused variable `x`

F841 Local variable `bar` is assigned to but never used
   --> F841_3.py:127:18
    |
125 | def f(provided: int) -> int:
126 |     match provided:
127 |         case Foo(bar) as x:
    |                  ^^^
128 |             pass
    |
help: Remove assignment to unused variable `bar`

F841 Local variable `x` is assigned to but never used
   --> F841_3.py:127:26
    |
125 | def f(provided: int) -> int:
126 |     match provided:
127 |         case Foo(bar) as x:
    |                          ^
128 |             pass
    |
help: Remove assignment to unused variable `x`

F841 Local variable `x` is assigned to but never used
   --> F841_3.py:133:27
    |
131 | def f(provided: int) -> int:
132 |     match provided:
133 |         case {"foo": 0, **x}:
    |                           ^
134 |             pass
    |
help: Remove assignment to unused variable `x`

F841 Local variable `x` is assigned to but never used
   --> F841_3.py:139:17
    |
137 | def f(provided: int) -> int:
138 |     match provided:
139 |         case {**x}:
    |                 ^
140 |             pass
    |
help: Remove assignment to unused variable `x`

F841 [*] Local variable `e` is assigned to but never used
   --> F841_3.py:155:17
    |
153 |     try:
154 |         print("hello")
155 |     except A as e :
    |                 ^
156 |         print("oh no!")
    |
help: Remove assignment to unused variable `e`
    |
154 |         print("hello")
    -     except A as e :
155 +     except A:
156 |         print("oh no!")
    |

F841 [*] Local variable `x` is assigned to but never used
   --> F841_3.py:160:5
    |
159 | def f():
160 |     x = 1
    |     ^
161 |     y = 2
    |
help: Remove assignment to unused variable `x`
    |
159 | def f():
    -     x = 1
160 |     y = 2
    |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `y` is assigned to but never used
   --> F841_3.py:161:5
    |
159 | def f():
160 |     x = 1
161 |     y = 2
    |     ^
    |
help: Remove assignment to unused variable `y`
    |
160 |     x = 1
    -     y = 2
161 |
    |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `x` is assigned to but never used
   --> F841_3.py:165:5
    |
164 | def f():
165 |     x = 1
    |     ^
166 |
167 |     y = 2
    |
help: Remove assignment to unused variable `x`
    |
164 | def f():
    -     x = 1
165 |
    |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `y` is assigned to but never used
   --> F841_3.py:167:5
    |
165 |     x = 1
166 |
167 |     y = 2
    |     ^
    |
help: Remove assignment to unused variable `y`
    |
166 |
    -     y = 2
167 |
    |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `x` is assigned to but never used
   --> F841_3.py:173:6
    |
171 |     (x) = foo()
172 |     ((x)) = foo()
173 |     (x) = (y.z) = foo()
    |      ^
    |
help: Remove assignment to unused variable `x`
    |
172 |     ((x)) = foo()
    -     (x) = (y.z) = foo()
173 +     (y.z) = foo()
    |
note: This is an unsafe fix and may change runtime behavior
