---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
snapshot_kind: text
---
B018.py:11:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
 9 |     "str"  # Str (no raise)
10 |     f"{int}"  # JoinedStr (no raise)
11 |     1j  # Number (complex)
   |     ^^ B018
12 |     1  # Number (int)
13 |     1.0  # Number (float)
   |

B018.py:12:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
10 |     f"{int}"  # JoinedStr (no raise)
11 |     1j  # Number (complex)
12 |     1  # Number (int)
   |     ^ B018
13 |     1.0  # Number (float)
14 |     b"foo"  # Binary
   |

B018.py:13:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
11 |     1j  # Number (complex)
12 |     1  # Number (int)
13 |     1.0  # Number (float)
   |     ^^^ B018
14 |     b"foo"  # Binary
15 |     True  # NameConstant (True)
   |

B018.py:14:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
12 |     1  # Number (int)
13 |     1.0  # Number (float)
14 |     b"foo"  # Binary
   |     ^^^^^^ B018
15 |     True  # NameConstant (True)
16 |     False  # NameConstant (False)
   |

B018.py:15:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
13 |     1.0  # Number (float)
14 |     b"foo"  # Binary
15 |     True  # NameConstant (True)
   |     ^^^^ B018
16 |     False  # NameConstant (False)
17 |     None  # NameConstant (None)
   |

B018.py:16:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
14 |     b"foo"  # Binary
15 |     True  # NameConstant (True)
16 |     False  # NameConstant (False)
   |     ^^^^^ B018
17 |     None  # NameConstant (None)
18 |     [1, 2]  # list
   |

B018.py:17:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
15 |     True  # NameConstant (True)
16 |     False  # NameConstant (False)
17 |     None  # NameConstant (None)
   |     ^^^^ B018
18 |     [1, 2]  # list
19 |     {1, 2}  # set
   |

B018.py:18:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
16 |     False  # NameConstant (False)
17 |     None  # NameConstant (None)
18 |     [1, 2]  # list
   |     ^^^^^^ B018
19 |     {1, 2}  # set
20 |     {"foo": "bar"}  # dict
   |

B018.py:19:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
17 |     None  # NameConstant (None)
18 |     [1, 2]  # list
19 |     {1, 2}  # set
   |     ^^^^^^ B018
20 |     {"foo": "bar"}  # dict
   |

B018.py:20:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
18 |     [1, 2]  # list
19 |     {1, 2}  # set
20 |     {"foo": "bar"}  # dict
   |     ^^^^^^^^^^^^^^ B018
   |

B018.py:24:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
23 | class Foo3:
24 |     123
   |     ^^^ B018
25 |     a = 2
26 |     "str"
   |

B018.py:27:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
25 |     a = 2
26 |     "str"
27 |     1
   |     ^ B018
   |

B018.py:39:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
37 |     "str"  # Str (no raise)
38 |     f"{int}"  # JoinedStr (no raise)
39 |     1j  # Number (complex)
   |     ^^ B018
40 |     1  # Number (int)
41 |     1.0  # Number (float)
   |

B018.py:40:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
38 |     f"{int}"  # JoinedStr (no raise)
39 |     1j  # Number (complex)
40 |     1  # Number (int)
   |     ^ B018
41 |     1.0  # Number (float)
42 |     b"foo"  # Binary
   |

B018.py:41:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
39 |     1j  # Number (complex)
40 |     1  # Number (int)
41 |     1.0  # Number (float)
   |     ^^^ B018
42 |     b"foo"  # Binary
43 |     True  # NameConstant (True)
   |

B018.py:42:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
40 |     1  # Number (int)
41 |     1.0  # Number (float)
42 |     b"foo"  # Binary
   |     ^^^^^^ B018
43 |     True  # NameConstant (True)
44 |     False  # NameConstant (False)
   |

B018.py:43:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
41 |     1.0  # Number (float)
42 |     b"foo"  # Binary
43 |     True  # NameConstant (True)
   |     ^^^^ B018
44 |     False  # NameConstant (False)
45 |     None  # NameConstant (None)
   |

B018.py:44:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
42 |     b"foo"  # Binary
43 |     True  # NameConstant (True)
44 |     False  # NameConstant (False)
   |     ^^^^^ B018
45 |     None  # NameConstant (None)
46 |     [1, 2]  # list
   |

B018.py:45:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
43 |     True  # NameConstant (True)
44 |     False  # NameConstant (False)
45 |     None  # NameConstant (None)
   |     ^^^^ B018
46 |     [1, 2]  # list
47 |     {1, 2}  # set
   |

B018.py:46:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
44 |     False  # NameConstant (False)
45 |     None  # NameConstant (None)
46 |     [1, 2]  # list
   |     ^^^^^^ B018
47 |     {1, 2}  # set
48 |     {"foo": "bar"}  # dict
   |

B018.py:47:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
45 |     None  # NameConstant (None)
46 |     [1, 2]  # list
47 |     {1, 2}  # set
   |     ^^^^^^ B018
48 |     {"foo": "bar"}  # dict
   |

B018.py:48:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
46 |     [1, 2]  # list
47 |     {1, 2}  # set
48 |     {"foo": "bar"}  # dict
   |     ^^^^^^^^^^^^^^ B018
   |

B018.py:52:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
51 | def foo3():
52 |     123
   |     ^^^ B018
53 |     a = 2
54 |     "str"
   |

B018.py:55:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
53 |     a = 2
54 |     "str"
55 |     3
   |     ^ B018
   |

B018.py:63:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
62 | def foo5():
63 |     foo.bar  # Attribute (raise)
   |     ^^^^^^^ B018
64 |     object().__class__  # Attribute (raise)
65 |     "foo" + "bar"  # BinOp (raise)
   |

B018.py:64:5: B018 Found useless attribute access. Either assign it to a variable or remove it.
   |
62 | def foo5():
63 |     foo.bar  # Attribute (raise)
64 |     object().__class__  # Attribute (raise)
   |     ^^^^^^^^^^^^^^^^^^ B018
65 |     "foo" + "bar"  # BinOp (raise)
   |

B018.py:65:5: B018 Found useless expression. Either assign it to a variable or remove it.
   |
63 |     foo.bar  # Attribute (raise)
64 |     object().__class__  # Attribute (raise)
65 |     "foo" + "bar"  # BinOp (raise)
   |     ^^^^^^^^^^^^^ B018
   |
