Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[refurb] Restrict delete-full-slice to lists (FURB131) - #27711

Merged
ntBre merged 2 commits into
astral-sh:mainfrom
AbhinavMir:furb131-list-only
Aug 14, 2026
Merged

[refurb] Restrict delete-full-slice to lists (FURB131)#27711
ntBre merged 2 commits into
astral-sh:mainfrom
AbhinavMir:furb131-list-only

Conversation

@AbhinavMir

@AbhinavMir AbhinavMir commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #27216

@astral-sh-bot
astral-sh-bot Bot requested a review from ntBre August 13, 2026 01:56

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good to me overall. I just had a few minor suggestions.

/// ## References
/// - [Python documentation: Mutable Sequence Types](https://docs.python.org/3/library/stdtypes.html?highlight=list#mutable-sequence-types)
/// - [Python documentation: `dict.clear()`](https://docs.python.org/3/library/stdtypes.html?highlight=list#dict.clear)
/// - [Python documentation: `list.clear()`](https://docs.python.org/3/library/stdtypes.html?highlight=list#mutable-sequence-types)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you intentionally link to this? I think this is the closer one:

Suggested change
/// - [Python documentation: `list.clear()`](https://docs.python.org/3/library/stdtypes.html?highlight=list#mutable-sequence-types)
/// - [Python documentation: `list.clear()`](https://docs.python.org/3/library/stdtypes.html?highlight=list#sequence.clear)

I tried list.clear first, but that redirects to this sequence.clear node.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I just used something available upstairs, and opened it and read something that made sense to me. I don't remember what anymore :/

Comment on lines +98 to +99
// It should only apply to variables that are known to be lists. `del d[:]` on a dict
// raises `KeyError` at runtime, so the rule must not apply to dicts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this comment will actually be helpful to future readers since from their perspective the rule doesn't apply to dicts anymore.

Suggested change
// It should only apply to variables that are known to be lists. `del d[:]` on a dict
// raises `KeyError` at runtime, so the rule must not apply to dicts.
// It should only apply to variables that are known to be lists.

Comment on lines +37 to +44
# `del d[:]` on a dict raises `KeyError` at runtime, so FURB131 must not apply to
# dicts. Regression coverage: these dict full-slice deletions must NOT be flagged.
del names[:]
del y, names[:], x


def no_dict_one(x: dict[int, str]):
# not FURB131

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to preserve these tests. As I mentioned in my other comment, I think it will just confuse future readers who aren't going to expect the rule to apply to dicts. If we do want to preserve dict tests, I would actually avoid modifying this file at all, which will make the removed diagnostics much clearer in the snapshot diff.

So I would either revert changes to this file or completely drop dict tests, not move the dict tests down here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you're right. I often sometimes overdocument previous behaviors, but isn't needed. Accepted, thank you!

@ntBre ntBre changed the title [refurb] Restrict FURB131 (delete-full-slice) to lists [refurb] Restrict delete-full-slice to lists (FURB131) Aug 13, 2026
@ntBre ntBre added rule Implementing or modifying a lint rule preview Related to preview mode features labels Aug 13, 2026
@astral-sh-bot

astral-sh-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

`del d[:]` on a dict raises `KeyError` at runtime, so suggesting
`dict.clear()` as an equivalent replacement is incorrect. Restrict the
rule to lists only, matching the upstream Refurb behavior.

Update the rule documentation and the fixture accordingly. The dict cases
are kept in the fixture as regression coverage to confirm they are no
longer flagged, while the list cases remain flagged.

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@ntBre
ntBre enabled auto-merge (squash) August 14, 2026 19:35
@ntBre
ntBre merged commit 89ac93b into astral-sh:main Aug 14, 2026
47 checks passed
George-Ogden pushed a commit to George-Ogden/ruff that referenced this pull request Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Related to preview mode features rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

delete-full-slice (FURB131) should not apply to dicts

2 participants