---
source: crates/ruff_linter/src/rules/ruff/mod.rs
---
RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:8:5
   |
 7 | if k in d:                          # Bare name
 8 |     del d[k]
   |     ^^^^^^^^
 9 |
10 | if '' in d:                         # String
   |
help: Replace `if` statement with `.pop(..., None)`
  |
6 |
  - if k in d:                          # Bare name
  -     del d[k]
7 + d.pop(k, None)
8 |
  |
note: This is an unsafe fix and may change runtime behavior

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:11:5
   |
10 | if '' in d:                         # String
11 |     del d[""]                       # Different quotes
   |     ^^^^^^^^^
12 |
13 | if b"" in d:                        # Bytes
   |
help: Replace `if` statement with `.pop(..., None)`
   |
9  |
   - if '' in d:                         # String
   -     del d[""]                       # Different quotes
10 + d.pop('', None)                       # Different quotes
11 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:14:5
   |
13 |   if b"" in d:                        # Bytes
14 | /     del d[                          # Multiline slice
15 | |         b''''''                     # Triple quotes
16 | |     ]
   | |_____^
17 |
18 |   if 0 in d: del d[0]                 # Single-line statement
   |
help: Replace `if` statement with `.pop(..., None)`
   |
12 |
   - if b"" in d:                        # Bytes
   -     del d[                          # Multiline slice
   -         b''''''                     # Triple quotes
   -     ]
13 + d.pop(b"", None)
14 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:18:12
   |
16 |     ]
17 |
18 | if 0 in d: del d[0]                 # Single-line statement
   |            ^^^^^^^^
19 |
20 | if 3j in d:                         # Complex
   |
help: Replace `if` statement with `.pop(..., None)`
   |
17 |
   - if 0 in d: del d[0]                 # Single-line statement
18 + d.pop(0, None)                 # Single-line statement
19 |
   |

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:21:5
   |
20 | if 3j in d:                         # Complex
21 |     del d[3j]
   |     ^^^^^^^^^
22 |
23 | if 0.1234 in d:                     # Float
   |
help: Replace `if` statement with `.pop(..., None)`
   |
19 |
   - if 3j in d:                         # Complex
   -     del d[3j]
20 + d.pop(3j, None)
21 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:24:5
   |
23 | if 0.1234 in d:                     # Float
24 |     del d[.1_2_3_4]                 # Number separators and shorthand syntax
   |     ^^^^^^^^^^^^^^^
25 |
26 | if True in d:                       # True
   |
help: Replace `if` statement with `.pop(..., None)`
   |
22 |
   - if 0.1234 in d:                     # Float
   -     del d[.1_2_3_4]                 # Number separators and shorthand syntax
23 + d.pop(0.1234, None)                 # Number separators and shorthand syntax
24 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:27:5
   |
26 | if True in d:                       # True
27 |     del d[True]
   |     ^^^^^^^^^^^
28 |
29 | if False in d:                      # False
   |
help: Replace `if` statement with `.pop(..., None)`
   |
25 |
   - if True in d:                       # True
   -     del d[True]
26 + d.pop(True, None)
27 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:30:5
   |
29 | if False in d:                      # False
30 |     del d[False]
   |     ^^^^^^^^^^^^
31 |
32 | if None in d:                       # None
   |
help: Replace `if` statement with `.pop(..., None)`
   |
28 |
   - if False in d:                      # False
   -     del d[False]
29 + d.pop(False, None)
30 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:33:5
   |
32 |   if None in d:                       # None
33 | /     del d[
34 | |         # Comment in the middle
35 | |         None
36 | |     ]
   | |_____^
37 |
38 |   if ... in d:                        # Ellipsis
   |
help: Replace `if` statement with `.pop(..., None)`
   |
31 |
   - if None in d:                       # None
   -     del d[
   -         # Comment in the middle
   -         None
   -     ]
32 + d.pop(None, None)
33 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:39:5
   |
38 |   if ... in d:                        # Ellipsis
39 | /     del d[
40 | |                                     # Comment in the middle, indented
41 | |         ...]
   | |____________^
42 |
43 |   if "a" "bc" in d:                   # String concatenation
   |
help: Replace `if` statement with `.pop(..., None)`
   |
37 |
   - if ... in d:                        # Ellipsis
   -     del d[
   -                                     # Comment in the middle, indented
   -         ...]
38 + d.pop(..., None)
39 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:44:5
   |
43 | if "a" "bc" in d:                   # String concatenation
44 |     del d['abc']
   |     ^^^^^^^^^^^^
45 |
46 | if r"\foo" in d:                    # Raw string
   |
help: Replace `if` statement with `.pop(..., None)`
   |
42 |
   - if "a" "bc" in d:                   # String concatenation
   -     del d['abc']
43 + d.pop("a" "bc", None)
44 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:47:5
   |
46 | if r"\foo" in d:                    # Raw string
47 |     del d['\\foo']
   |     ^^^^^^^^^^^^^^
48 |
49 | if b'yt' b'es' in d:                # Bytes concatenation
   |
help: Replace `if` statement with `.pop(..., None)`
   |
45 |
   - if r"\foo" in d:                    # Raw string
   -     del d['\\foo']
46 + d.pop(r"\foo", None)
47 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:50:5
   |
49 | if b'yt' b'es' in d:                # Bytes concatenation
50 |     del d[rb"""ytes"""]             # Raw bytes
   |     ^^^^^^^^^^^^^^^^^^^
51 |
52 | if k in d:
   |
help: Replace `if` statement with `.pop(..., None)`
   |
48 |
   - if b'yt' b'es' in d:                # Bytes concatenation
   -     del d[rb"""ytes"""]             # Raw bytes
49 + d.pop(b'yt' b'es', None)             # Raw bytes
50 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:54:5
   |
52 | if k in d:
53 |     # comment that gets dropped
54 |     del d[k]
   |     ^^^^^^^^
55 |
56 | ### Safely fixable
   |
help: Replace `if` statement with `.pop(..., None)`
   |
51 |
   - if k in d:
   -     # comment that gets dropped
   -     del d[k]
52 + d.pop(k, None)
53 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:59:5
   |
58 | if k in d:
59 |     del d[k]
   |     ^^^^^^^^
60 |
61 | if '' in d:
   |
help: Replace `if` statement with `.pop(..., None)`
   |
57 |
   - if k in d:
   -     del d[k]
58 + d.pop(k, None)
59 |
   |

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:62:5
   |
61 | if '' in d:
62 |     del d[""]
   |     ^^^^^^^^^
63 |
64 | if b"" in d:
   |
help: Replace `if` statement with `.pop(..., None)`
   |
60 |
   - if '' in d:
   -     del d[""]
61 + d.pop('', None)
62 |
   |

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:65:5
   |
64 |   if b"" in d:
65 | /     del d[
66 | |         b''''''
67 | |     ]
   | |_____^
68 |
69 |   if 0 in d: del d[0]
   |
help: Replace `if` statement with `.pop(..., None)`
   |
63 |
   - if b"" in d:
   -     del d[
   -         b''''''
   -     ]
64 + d.pop(b"", None)
65 |
   |

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:69:12
   |
67 |     ]
68 |
69 | if 0 in d: del d[0]
   |            ^^^^^^^^
70 |
71 | if 3j in d:
   |
help: Replace `if` statement with `.pop(..., None)`
   |
68 |
   - if 0 in d: del d[0]
69 + d.pop(0, None)
70 |
   |

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:72:5
   |
71 | if 3j in d:
72 |     del d[3j]
   |     ^^^^^^^^^
73 |
74 | if 0.1234 in d:
   |
help: Replace `if` statement with `.pop(..., None)`
   |
70 |
   - if 3j in d:
   -     del d[3j]
71 + d.pop(3j, None)
72 |
   |

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:75:5
   |
74 | if 0.1234 in d:
75 |     del d[.1_2_3_4]
   |     ^^^^^^^^^^^^^^^
76 |
77 | if True in d:
   |
help: Replace `if` statement with `.pop(..., None)`
   |
73 |
   - if 0.1234 in d:
   -     del d[.1_2_3_4]
74 + d.pop(0.1234, None)
75 |
   |

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:78:5
   |
77 | if True in d:
78 |     del d[True]
   |     ^^^^^^^^^^^
79 |
80 | if False in d:
   |
help: Replace `if` statement with `.pop(..., None)`
   |
76 |
   - if True in d:
   -     del d[True]
77 + d.pop(True, None)
78 |
   |

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:81:5
   |
80 | if False in d:
81 |     del d[False]
   |     ^^^^^^^^^^^^
82 |
83 | if None in d:
   |
help: Replace `if` statement with `.pop(..., None)`
   |
79 |
   - if False in d:
   -     del d[False]
80 + d.pop(False, None)
81 |
   |

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:84:5
   |
83 |   if None in d:
84 | /     del d[
85 | |         None
86 | |     ]
   | |_____^
87 |
88 |   if ... in d:
   |
help: Replace `if` statement with `.pop(..., None)`
   |
82 |
   - if None in d:
   -     del d[
   -         None
   -     ]
83 + d.pop(None, None)
84 |
   |

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:89:5
   |
88 |   if ... in d:
89 | /     del d[
90 | |         ...]
   | |____________^
91 |
92 |   if "a" "bc" in d:
   |
help: Replace `if` statement with `.pop(..., None)`
   |
87 |
   - if ... in d:
   -     del d[
   -         ...]
88 + d.pop(..., None)
89 |
   |

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:93:5
   |
92 | if "a" "bc" in d:
93 |     del d['abc']
   |     ^^^^^^^^^^^^
94 |
95 | if r"\foo" in d:
   |
help: Replace `if` statement with `.pop(..., None)`
   |
91 |
   - if "a" "bc" in d:
   -     del d['abc']
92 + d.pop("a" "bc", None)
93 |
   |

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:96:5
   |
95 | if r"\foo" in d:
96 |     del d['\\foo']
   |     ^^^^^^^^^^^^^^
97 |
98 | if b'yt' b'es' in d:
   |
help: Replace `if` statement with `.pop(..., None)`
   |
94 |
   - if r"\foo" in d:
   -     del d['\\foo']
95 + d.pop(r"\foo", None)
96 |
   |

RUF051 [*] Use `pop` instead of `key in dict` followed by `del dict[key]`
  --> RUF051.py:99:5
   |
98 | if b'yt' b'es' in d:
99 |     del d[rb"""ytes"""]             # This should not make the fix unsafe
   |     ^^^^^^^^^^^^^^^^^^^
   |
help: Replace `if` statement with `.pop(..., None)`
   |
97 |
   - if b'yt' b'es' in d:
   -     del d[rb"""ytes"""]             # This should not make the fix unsafe
98 + d.pop(b'yt' b'es', None)             # This should not make the fix unsafe
99 |
   |
