---
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
---
F841 [*] Local variable `e` is assigned to but never used
 --> F841_0.py:3:22
  |
1 | try:
2 |     1 / 0
3 | except ValueError as e:
  |                      ^
4 |     pass
  |
help: Remove assignment to unused variable `e`
  |
2 |     1 / 0
  - except ValueError as e:
3 + except ValueError:
4 |     pass
  |

F841 [*] Local variable `foo` is assigned to but never used
  --> F841_0.py:20:5
   |
19 | def f():
20 |     foo = (1, 2)
   |     ^^^
21 |     (a, b) = (1, 2)
   |
help: Remove assignment to unused variable `foo`
   |
19 | def f():
   -     foo = (1, 2)
20 |     (a, b) = (1, 2)
   |
note: This is an unsafe fix and may change runtime behavior

F841 Local variable `a` is assigned to but never used
  --> F841_0.py:21:6
   |
19 | def f():
20 |     foo = (1, 2)
21 |     (a, b) = (1, 2)
   |      ^
22 |
23 |     bar = (1, 2)
   |
help: Remove assignment to unused variable `a`

F841 Local variable `b` is assigned to but never used
  --> F841_0.py:21:9
   |
19 | def f():
20 |     foo = (1, 2)
21 |     (a, b) = (1, 2)
   |         ^
22 |
23 |     bar = (1, 2)
   |
help: Remove assignment to unused variable `b`

F841 [*] Local variable `baz` is assigned to but never used
  --> F841_0.py:26:14
   |
24 |     (c, d) = bar
25 |
26 |     (x, y) = baz = bar
   |              ^^^
   |
help: Remove assignment to unused variable `baz`
   |
25 |
   -     (x, y) = baz = bar
26 +     (x, y) = bar
27 |
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `_` is assigned to but never used
  --> F841_0.py:35:5
   |
34 | def f():
35 |     _ = 1
   |     ^
36 |     __ = 1
37 |     _discarded = 1
   |
help: Remove assignment to unused variable `_`
   |
34 | def f():
   -     _ = 1
35 |     __ = 1
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `__` is assigned to but never used
  --> F841_0.py:36:5
   |
34 | def f():
35 |     _ = 1
36 |     __ = 1
   |     ^^
37 |     _discarded = 1
   |
help: Remove assignment to unused variable `__`
   |
35 |     _ = 1
   -     __ = 1
36 |     _discarded = 1
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `_discarded` is assigned to but never used
  --> F841_0.py:37:5
   |
35 |     _ = 1
36 |     __ = 1
37 |     _discarded = 1
   |     ^^^^^^^^^^
   |
help: Remove assignment to unused variable `_discarded`
   |
36 |     __ = 1
   -     _discarded = 1
37 |
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `b` is assigned to but never used
  --> F841_0.py:51:9
   |
49 |     def c():
50 |         # F841
51 |         b = 1
   |         ^
52 |
53 |     def d():
   |
help: Remove assignment to unused variable `b`
   |
50 |         # F841
   -         b = 1
51 +         pass
52 |
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `my_file` is assigned to but never used
  --> F841_0.py:79:26
   |
78 | def f():
79 |     with open("file") as my_file, open("") as ((this, that)):
   |                          ^^^^^^^
80 |         print("hello")
   |
help: Remove assignment to unused variable `my_file`
   |
78 | def f():
   -     with open("file") as my_file, open("") as ((this, that)):
79 +     with open("file"), open("") as ((this, that)):
80 |         print("hello")
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `my_file` is assigned to but never used
  --> F841_0.py:85:25
   |
83 | def f():
84 |     with (
85 |         open("file") as my_file,
   |                         ^^^^^^^
86 |         open("") as ((this, that)),
87 |     ):
   |
help: Remove assignment to unused variable `my_file`
   |
84 |     with (
   -         open("file") as my_file,
85 +         open("file"),
86 |         open("") as ((this, that)),
   |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `msg3` is assigned to but never used
   --> F841_0.py:102:5
    |
100 |     msg1 = "Hello, world!"
101 |     msg2 = "Hello, world!"
102 |     msg3 = "Hello, world!"
    |     ^^^^
103 |     match x:
104 |         case 1:
    |
help: Remove assignment to unused variable `msg3`
    |
101 |     msg2 = "Hello, world!"
    -     msg3 = "Hello, world!"
102 |     match x:
    |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `Baz` is assigned to but never used
   --> F841_0.py:115:5
    |
113 |     Foo = enum.Enum("Foo", "A B")
114 |     Bar = enum.Enum("Bar", "A B")
115 |     Baz = enum.Enum("Baz", "A B")
    |     ^^^
116 |
117 |     match x:
    |
help: Remove assignment to unused variable `Baz`
    |
114 |     Bar = enum.Enum("Bar", "A B")
    -     Baz = enum.Enum("Baz", "A B")
115 +     enum.Enum("Baz", "A B")
116 |
    |
note: This is an unsafe fix and may change runtime behavior

F841 Local variable `y` is assigned to but never used
   --> F841_0.py:122:14
    |
120 |         case [Bar.A, *_]:
121 |             print("A")
122 |         case y:
    |              ^
123 |             pass
    |
help: Remove assignment to unused variable `y`

F841 Local variable `value` is assigned to but never used
   --> F841_0.py:127:21
    |
126 | def f():
127 |     if any((key := (value := x)) for x in ["ok"]):
    |                     ^^^^^
128 |         print(key)
    |
help: Remove assignment to unused variable `value`

F841 [*] Local variable `_` is assigned to but never used
   --> F841_0.py:152:25
    |
150 |     try:
151 |         pass
152 |     except Exception as _:
    |                         ^
153 |         pass
    |
help: Remove assignment to unused variable `_`
    |
151 |         pass
    -     except Exception as _:
152 +     except Exception:
153 |         pass
    |

F841 [*] Local variable `__class__` is assigned to but never used
   --> F841_0.py:168:9
    |
166 | class A:
167 |     def set_class(self, cls):
168 |         __class__ = cls  # F841
    |         ^^^^^^^^^
    |
help: Remove assignment to unused variable `__class__`
    |
167 |     def set_class(self, cls):
    -         __class__ = cls  # F841
168 +         pass  # F841
169 |
    |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `__class__` is assigned to but never used
   --> F841_0.py:174:13
    |
172 |     class B:
173 |         def set_class(self, cls):
174 |             __class__ = cls  # F841
    |             ^^^^^^^^^
    |
help: Remove assignment to unused variable `__class__`
    |
173 |         def set_class(self, cls):
    -             __class__ = cls  # F841
174 +             pass  # F841
175 |
    |
note: This is an unsafe fix and may change runtime behavior

F841 [*] Local variable `__class__` is assigned to but never used
   --> F841_0.py:182:17
    |
180 |             print(__class__)
181 |             def set_class(self, cls):
182 |                 __class__ = cls  # F841
    |                 ^^^^^^^^^
    |
help: Remove assignment to unused variable `__class__`
    |
181 |             def set_class(self, cls):
    -                 __class__ = cls  # F841
182 +                 pass  # F841
183 |
    |
note: This is an unsafe fix and may change runtime behavior
