[ruff] Fix non-triggering example for if-key-in-dict-del (RUF051) - #26433
Merged
ntBre merged 1 commit intoJul 6, 2026
Merged
Conversation
…UF051)
RUF051 only fires when the dictionary is known to be of type `dict`
(`typing::is_known_to_be_of_type_dict`). The docstring's "## Example" used a
bare, unbound `dictionary`, whose type can't be inferred, so the example does
not actually trigger the rule:
$ printf 'if key in dictionary:\n del dictionary[key]\n' \
| ruff check --select RUF051 -
All checks passed!
Bind `dictionary = {}` in both code blocks so the example triggers, matching
the convention used by the sibling dict-type-gated rule
`if-else-block-instead-of-dict-get` (SIM401), whose example likewise binds
`foo = {}`. Docstring-only; no behavior change.
if-key-in-dict-del (RUF051)ruff] Fix non-triggering example for if-key-in-dict-del (RUF051)
ntBre
enabled auto-merge (squash)
July 6, 2026 22:03
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
if-key-in-dict-del(RUF051) rule docstring's## Exampledoes not actually trigger the rule.RUF051 only fires when the dictionary is known to be of type
dict(typing::is_known_to_be_of_type_dict). The example used a bare, unbounddictionary, whose type can't be inferred — so the snippet presented as triggering is in fact clean:Change
Bind
dictionary = {}in both code blocks so the example triggers (and the "Use instead" stays parallel). Docstring-only; no behavior change.This matches the convention already used by the sibling dict-type-gated rule
if-else-block-instead-of-dict-get(SIM401), whose docstring example likewise bindsfoo = {}.Test plan
cargo dev generate-docsregeneratesdocs/rules/if-key-in-dict-del.mdcleanly.scripts/check_docs_formatted.py→All docs are formatted correctly.