---
source: crates/ruff_linter/src/rules/ruff/mod.rs
---
RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:117:43
    |
116 | # dict.get in ternary expression
117 | value = "not found" if my_dict.get("key", False) else "default"  # [RUF056]
    |                                           ^^^^^
118 |
119 | # dict.get in an if statement
    |
help: Remove falsy fallback from `dict.get()`
    |
116 | # dict.get in ternary expression
    - value = "not found" if my_dict.get("key", False) else "default"  # [RUF056]
117 + value = "not found" if my_dict.get("key") else "default"  # [RUF056]
118 |
    |

RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:120:23
    |
119 | # dict.get in an if statement
120 | if my_dict.get("key", False):  # [RUF056]
    |                       ^^^^^
121 |     pass
    |
help: Remove falsy fallback from `dict.get()`
    |
119 | # dict.get in an if statement
    - if my_dict.get("key", False):  # [RUF056]
120 + if my_dict.get("key"):  # [RUF056]
121 |     pass
    |

RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:124:32
    |
123 | # dict.get in compound if statement
124 | if True and my_dict.get("key", False):  # [RUF056]
    |                                ^^^^^
125 |     pass
    |
help: Remove falsy fallback from `dict.get()`
    |
123 | # dict.get in compound if statement
    - if True and my_dict.get("key", False):  # [RUF056]
124 + if True and my_dict.get("key"):  # [RUF056]
125 |     pass
    |

RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:127:23
    |
125 |     pass
126 |
127 | if my_dict.get("key", False) or True:  # [RUF056]
    |                       ^^^^^
128 |     pass
    |
help: Remove falsy fallback from `dict.get()`
    |
126 |
    - if my_dict.get("key", False) or True:  # [RUF056]
127 + if my_dict.get("key") or True:  # [RUF056]
128 |     pass
    |

RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:131:27
    |
130 | # dict.get in an assert statement
131 | assert my_dict.get("key", False)  # [RUF056]
    |                           ^^^^^
132 |
133 | # dict.get in a while statement
    |
help: Remove falsy fallback from `dict.get()`
    |
130 | # dict.get in an assert statement
    - assert my_dict.get("key", False)  # [RUF056]
131 + assert my_dict.get("key")  # [RUF056]
132 |
    |

RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:134:26
    |
133 | # dict.get in a while statement
134 | while my_dict.get("key", False):  # [RUF056]
    |                          ^^^^^
135 |     pass
    |
help: Remove falsy fallback from `dict.get()`
    |
133 | # dict.get in a while statement
    - while my_dict.get("key", False):  # [RUF056]
134 + while my_dict.get("key"):  # [RUF056]
135 |     pass
    |

RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:138:32
    |
137 | # dict.get in unary not expression
138 | value = not my_dict.get("key", False)  # [RUF056]
    |                                ^^^^^
139 |
140 | # testing all falsy fallbacks
    |
help: Remove falsy fallback from `dict.get()`
    |
137 | # dict.get in unary not expression
    - value = not my_dict.get("key", False)  # [RUF056]
138 + value = not my_dict.get("key")  # [RUF056]
139 |
    |

RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:141:32
    |
140 | # testing all falsy fallbacks
141 | value = not my_dict.get("key", False)  # [RUF056]
    |                                ^^^^^
142 | value = not my_dict.get("key", [])  # [RUF056]
143 | value = not my_dict.get("key", list())  # [RUF056]
    |
help: Remove falsy fallback from `dict.get()`
    |
140 | # testing all falsy fallbacks
    - value = not my_dict.get("key", False)  # [RUF056]
141 + value = not my_dict.get("key")  # [RUF056]
142 | value = not my_dict.get("key", [])  # [RUF056]
    |

RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:142:32
    |
140 | # testing all falsy fallbacks
141 | value = not my_dict.get("key", False)  # [RUF056]
142 | value = not my_dict.get("key", [])  # [RUF056]
    |                                ^^
143 | value = not my_dict.get("key", list())  # [RUF056]
144 | value = not my_dict.get("key", {})  # [RUF056]
    |
help: Remove falsy fallback from `dict.get()`
    |
141 | value = not my_dict.get("key", False)  # [RUF056]
    - value = not my_dict.get("key", [])  # [RUF056]
142 + value = not my_dict.get("key")  # [RUF056]
143 | value = not my_dict.get("key", list())  # [RUF056]
    |

RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:143:32
    |
141 | value = not my_dict.get("key", False)  # [RUF056]
142 | value = not my_dict.get("key", [])  # [RUF056]
143 | value = not my_dict.get("key", list())  # [RUF056]
    |                                ^^^^^^
144 | value = not my_dict.get("key", {})  # [RUF056]
145 | value = not my_dict.get("key", dict())  # [RUF056]
    |
help: Remove falsy fallback from `dict.get()`
    |
142 | value = not my_dict.get("key", [])  # [RUF056]
    - value = not my_dict.get("key", list())  # [RUF056]
143 + value = not my_dict.get("key")  # [RUF056]
144 | value = not my_dict.get("key", {})  # [RUF056]
    |

RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:144:32
    |
142 | value = not my_dict.get("key", [])  # [RUF056]
143 | value = not my_dict.get("key", list())  # [RUF056]
144 | value = not my_dict.get("key", {})  # [RUF056]
    |                                ^^
145 | value = not my_dict.get("key", dict())  # [RUF056]
146 | value = not my_dict.get("key", set())  # [RUF056]
    |
help: Remove falsy fallback from `dict.get()`
    |
143 | value = not my_dict.get("key", list())  # [RUF056]
    - value = not my_dict.get("key", {})  # [RUF056]
144 + value = not my_dict.get("key")  # [RUF056]
145 | value = not my_dict.get("key", dict())  # [RUF056]
    |

RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:145:32
    |
143 | value = not my_dict.get("key", list())  # [RUF056]
144 | value = not my_dict.get("key", {})  # [RUF056]
145 | value = not my_dict.get("key", dict())  # [RUF056]
    |                                ^^^^^^
146 | value = not my_dict.get("key", set())  # [RUF056]
147 | value = not my_dict.get("key", None)  # [RUF056]
    |
help: Remove falsy fallback from `dict.get()`
    |
144 | value = not my_dict.get("key", {})  # [RUF056]
    - value = not my_dict.get("key", dict())  # [RUF056]
145 + value = not my_dict.get("key")  # [RUF056]
146 | value = not my_dict.get("key", set())  # [RUF056]
    |

RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:146:32
    |
144 | value = not my_dict.get("key", {})  # [RUF056]
145 | value = not my_dict.get("key", dict())  # [RUF056]
146 | value = not my_dict.get("key", set())  # [RUF056]
    |                                ^^^^^
147 | value = not my_dict.get("key", None)  # [RUF056]
148 | value = not my_dict.get("key", 0)  # [RUF056]
    |
help: Remove falsy fallback from `dict.get()`
    |
145 | value = not my_dict.get("key", dict())  # [RUF056]
    - value = not my_dict.get("key", set())  # [RUF056]
146 + value = not my_dict.get("key")  # [RUF056]
147 | value = not my_dict.get("key", None)  # [RUF056]
    |

RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:147:32
    |
145 | value = not my_dict.get("key", dict())  # [RUF056]
146 | value = not my_dict.get("key", set())  # [RUF056]
147 | value = not my_dict.get("key", None)  # [RUF056]
    |                                ^^^^
148 | value = not my_dict.get("key", 0)  # [RUF056]
149 | value = not my_dict.get("key", 0.0)  # [RUF056]
    |
help: Remove falsy fallback from `dict.get()`
    |
146 | value = not my_dict.get("key", set())  # [RUF056]
    - value = not my_dict.get("key", None)  # [RUF056]
147 + value = not my_dict.get("key")  # [RUF056]
148 | value = not my_dict.get("key", 0)  # [RUF056]
    |

RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:148:32
    |
146 | value = not my_dict.get("key", set())  # [RUF056]
147 | value = not my_dict.get("key", None)  # [RUF056]
148 | value = not my_dict.get("key", 0)  # [RUF056]
    |                                ^
149 | value = not my_dict.get("key", 0.0)  # [RUF056]
150 | value = not my_dict.get("key", "")  # [RUF056]
    |
help: Remove falsy fallback from `dict.get()`
    |
147 | value = not my_dict.get("key", None)  # [RUF056]
    - value = not my_dict.get("key", 0)  # [RUF056]
148 + value = not my_dict.get("key")  # [RUF056]
149 | value = not my_dict.get("key", 0.0)  # [RUF056]
    |

RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:149:32
    |
147 | value = not my_dict.get("key", None)  # [RUF056]
148 | value = not my_dict.get("key", 0)  # [RUF056]
149 | value = not my_dict.get("key", 0.0)  # [RUF056]
    |                                ^^^
150 | value = not my_dict.get("key", "")  # [RUF056]
    |
help: Remove falsy fallback from `dict.get()`
    |
148 | value = not my_dict.get("key", 0)  # [RUF056]
    - value = not my_dict.get("key", 0.0)  # [RUF056]
149 + value = not my_dict.get("key")  # [RUF056]
150 | value = not my_dict.get("key", "")  # [RUF056]
    |

RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:150:32
    |
148 | value = not my_dict.get("key", 0)  # [RUF056]
149 | value = not my_dict.get("key", 0.0)  # [RUF056]
150 | value = not my_dict.get("key", "")  # [RUF056]
    |                                ^^
151 |
152 | # testing invalid dict.get call with inline comment
    |
help: Remove falsy fallback from `dict.get()`
    |
149 | value = not my_dict.get("key", 0.0)  # [RUF056]
    - value = not my_dict.get("key", "")  # [RUF056]
150 + value = not my_dict.get("key")  # [RUF056]
151 |
    |

RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:154:22
    |
152 | # testing invalid dict.get call with inline comment
153 | value = not my_dict.get("key", # comment1
154 |                      [] # comment2
    |                      ^^
155 |                      ) # [RUF056]
    |
help: Remove falsy fallback from `dict.get()`
    |
152 | # testing invalid dict.get call with inline comment
    - value = not my_dict.get("key", # comment1
    -                      [] # comment2
153 + value = not my_dict.get("key" # comment2
154 |                      ) # [RUF056]
    |
note: This is an unsafe fix and may change runtime behavior

RUF056 Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:163:24
    |
162 | # extra positional
163 | not my_dict.get("key", False, "?!")
    |                        ^^^^^
164 |
165 | # `default` is positional-only, so these are invalid
    |
help: Remove falsy fallback from `dict.get()`

RUF056 Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:166:24
    |
165 | # `default` is positional-only, so these are invalid
166 | not my_dict.get("key", default=False)
    |                        ^^^^^^^^^^^^^
167 | not my_dict.get(key="key", default=False)
168 | not my_dict.get(default=[], key="key")
    |
help: Remove falsy fallback from `dict.get()`

RUF056 Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:167:28
    |
165 | # `default` is positional-only, so these are invalid
166 | not my_dict.get("key", default=False)
167 | not my_dict.get(key="key", default=False)
    |                            ^^^^^^^^^^^^^
168 | not my_dict.get(default=[], key="key")
169 | not my_dict.get(default=False)
    |
help: Remove falsy fallback from `dict.get()`

RUF056 Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:168:17
    |
166 | not my_dict.get("key", default=False)
167 | not my_dict.get(key="key", default=False)
168 | not my_dict.get(default=[], key="key")
    |                 ^^^^^^^^^^
169 | not my_dict.get(default=False)
170 | not my_dict.get(key="key", other="something", default=False)
    |
help: Remove falsy fallback from `dict.get()`

RUF056 Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:169:17
    |
167 | not my_dict.get(key="key", default=False)
168 | not my_dict.get(default=[], key="key")
169 | not my_dict.get(default=False)
    |                 ^^^^^^^^^^^^^
170 | not my_dict.get(key="key", other="something", default=False)
171 | not my_dict.get(default=False, other="something", key="test")
    |
help: Remove falsy fallback from `dict.get()`

RUF056 Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:170:47
    |
168 | not my_dict.get(default=[], key="key")
169 | not my_dict.get(default=False)
170 | not my_dict.get(key="key", other="something", default=False)
    |                                               ^^^^^^^^^^^^^
171 | not my_dict.get(default=False, other="something", key="test")
    |
help: Remove falsy fallback from `dict.get()`

RUF056 Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:171:17
    |
169 | not my_dict.get(default=False)
170 | not my_dict.get(key="key", other="something", default=False)
171 | not my_dict.get(default=False, other="something", key="test")
    |                 ^^^^^^^^^^^^^
172 |
173 | # comments don't really matter here because of the kwargs but include them for
    |
help: Remove falsy fallback from `dict.get()`

RUF056 Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:177:5
    |
175 | not my_dict.get(
176 |     key="key",  # comment1
177 |     default=False,  # comment2
    |     ^^^^^^^^^^^^^
178 | )  # comment 3
179 | not my_dict.get(
    |
help: Remove falsy fallback from `dict.get()`

RUF056 Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:180:5
    |
178 | )  # comment 3
179 | not my_dict.get(
180 |     default=[],  # comment1
    |     ^^^^^^^^^^
181 |     key="key",  # comment2
182 | )  # comment 3
    |
help: Remove falsy fallback from `dict.get()`

RUF056 Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:187:24
    |
185 | # TypeError is raised at runtime before and after the fix, but we still bail
186 | # out for having an unrecognized number of arguments
187 | not my_dict.get("key", False, foo=...)
    |                        ^^^^^
188 |
189 | # https://github.com/astral-sh/ruff/issues/18798
    |
help: Remove falsy fallback from `dict.get()`

RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in boolean test positions. The default fallback `None` is already falsy.
   --> RUF056.py:191:19
    |
189 | # https://github.com/astral-sh/ruff/issues/18798
190 | d = {}
191 | not d.get("key", (False))
    |                   ^^^^^
    |
help: Remove falsy fallback from `dict.get()`
    |
190 | d = {}
    - not d.get("key", (False))
191 + not d.get("key")
    |
