Skip to content

Comments

[refurb] Also report non-name expressions (FURB169)#15905

Merged
MichaReiser merged 5 commits intoastral-sh:mainfrom
InSyncWithFoo:FURB169
Feb 5, 2025
Merged

[refurb] Also report non-name expressions (FURB169)#15905
MichaReiser merged 5 commits intoastral-sh:mainfrom
InSyncWithFoo:FURB169

Conversation

@InSyncWithFoo
Copy link
Contributor

@InSyncWithFoo InSyncWithFoo commented Feb 3, 2025

Summary

Follow-up to #15779.

Prior to this change, non-name expressions are not reported at all:

type(a.b) is type(None)  # no error

This change enhances the rule so that such cases are also reported in preview. Additionally:

  • The fix will now be marked as unsafe if there are any comments within its range.
  • Error messages are slightly modified.

Test Plan

cargo nextest run and cargo insta test.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@AlexWaygood AlexWaygood added the rule Implementing or modifying a lint rule label Feb 3, 2025
@AlexWaygood
Copy link
Member

None of the aforementioned changes are preview-gated, as they are considered bugfixes/non-breaking, similar to that of #15779.

We discussed this internally and, while it's quite borderline, we think this unfortunately does need to be gated behind preview. It's similar to #15579, and it's true that #15579 increased the scope a little bit, but it felt like #15579 was mainly a bugfix (expanding the scope of the rule was sort-of incidental). The line here is a bit fuzzy, and it's true that this could also be considered a bugfix of sorts. However, Ruff arguably isn't doing anything wrong here right now (it could just be doing a bit better). To us this feels like it's a significant enough expansion of the rule that it should be a preview-only change first.

@InSyncWithFoo
Copy link
Contributor Author

[...] this feels like it's a significant enough expansion of the rule that it should be a preview-only change first.

Preview-gated the first change. The other two are fine, I suppose?

@AlexWaygood
Copy link
Member

[...] this feels like it's a significant enough expansion of the rule that it should be a preview-only change first.

Preview-gated the first change. The other two are fine, I suppose?

yup! Thanks!

@MichaReiser MichaReiser added the preview Related to preview mode features label Feb 5, 2025
@MichaReiser MichaReiser merged commit 5852217 into astral-sh:main Feb 5, 2025
21 checks passed
@InSyncWithFoo InSyncWithFoo deleted the FURB169 branch February 5, 2025 08:10
MichaReiser added a commit that referenced this pull request Mar 13, 2025
## Summary

This PR stabilizes the preview behavior introduced in
#15905

The behavior change is that the rule now also recognizes `type(expr) is
type(None)` comparisons where `expr` isn't a name expression.
For example, the rule now detects `type(a.b) is type(None)` and suggests
rewriting the comparison to `a.b is None`.

The new behavior was introduced with Ruff 0.9.5 (6th of February), about
a month ago. There are no open issues or PRs related to this rule (or
behavior change).
MichaReiser added a commit that referenced this pull request Mar 13, 2025
## Summary

This PR stabilizes the preview behavior introduced in
#15905

The behavior change is that the rule now also recognizes `type(expr) is
type(None)` comparisons where `expr` isn't a name expression.
For example, the rule now detects `type(a.b) is type(None)` and suggests
rewriting the comparison to `a.b is None`.

The new behavior was introduced with Ruff 0.9.5 (6th of February), about
a month ago. There are no open issues or PRs related to this rule (or
behavior change).
MichaReiser added a commit that referenced this pull request Mar 13, 2025
## Summary

This PR stabilizes the preview behavior introduced in
#15905

The behavior change is that the rule now also recognizes `type(expr) is
type(None)` comparisons where `expr` isn't a name expression.
For example, the rule now detects `type(a.b) is type(None)` and suggests
rewriting the comparison to `a.b is None`.

The new behavior was introduced with Ruff 0.9.5 (6th of February), about
a month ago. There are no open issues or PRs related to this rule (or
behavior change).
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.

3 participants