Skip to content

[ruff] Recognize t-strings, generators, and lambdas in invalid-index-type (RUF016)#20213

Merged
dylwil3 merged 2 commits intoastral-sh:mainfrom
TaKO8Ki:invalid-index-type-for-bool-generator-lambda
Sep 12, 2025
Merged

[ruff] Recognize t-strings, generators, and lambdas in invalid-index-type (RUF016)#20213
dylwil3 merged 2 commits intoastral-sh:mainfrom
TaKO8Ki:invalid-index-type-for-bool-generator-lambda

Conversation

@TaKO8Ki
Copy link
Copy Markdown
Contributor

@TaKO8Ki TaKO8Ki commented Sep 3, 2025

Summary

Fixes #20204

Recognize t-strings, generators, and lambdas in RUF016

  • Accept boolean literals as valid index and slice bounds.
  • Add TString, Generator, and Lambda to CheckableExprType.
  • Expand RUF016.py fixture and update snapshots accordingly.

Test Plan

I've added test cases for t-string, generator and lambda to RUF016.py.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Sep 3, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dylwil3 dylwil3 self-requested a review September 9, 2025 12:55
Copy link
Copy Markdown
Collaborator

@dylwil3 dylwil3 left a comment

Choose a reason for hiding this comment

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

Thanks! I think this looks right, but it's hard to review the snapshot until the fixtures get moved to the end, so I'll take a second look once you've done that 😄

fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::FString => f.write_str("str"),
Self::TString => f.write_str("str"),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

t-strings do not have type str but rather type Template (or string.templatelib.Template)

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.

I changed it to Template.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you move the new fixtures to the end and put a comment with a link to the issue? It makes the diff in the snapshot a little easier to review since it doesn't change all the line numbers

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.

I've moved them to the end of the file.

@TaKO8Ki TaKO8Ki force-pushed the invalid-index-type-for-bool-generator-lambda branch from 91648d0 to 70b7075 Compare September 12, 2025 18:18
@TaKO8Ki TaKO8Ki requested a review from dylwil3 September 12, 2025 18:20
Copy link
Copy Markdown
Collaborator

@dylwil3 dylwil3 left a comment

Choose a reason for hiding this comment

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

Excellent, thank you!

@dylwil3 dylwil3 changed the title [ruff] Recognize t-strings, generators, and lambdas in RUF016 [ruff] Recognize t-strings, generators, and lambdas in invalid-index-type (RUF016) Sep 12, 2025
@dylwil3 dylwil3 added bug Something isn't working rule Implementing or modifying a lint rule labels Sep 12, 2025
@dylwil3 dylwil3 merged commit ff677a9 into astral-sh:main Sep 12, 2025
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

invalid-index-type (RUF016) has false negatives and false positives

2 participants