Skip to content

[ruff] Fix missing check on unrecognized early bound (RUF016) - #26986

Merged
ntBre merged 2 commits into
astral-sh:mainfrom
Andrej730:invalid-index-type-unrecog-bound
Jul 20, 2026
Merged

ntBre merged 2 commits into
astral-sh:mainfrom
Andrej730:invalid-index-type-unrecog-bound

Conversation

@Andrej730

Copy link
Copy Markdown
Contributor

Summary

Noticed a bug in invalid_index_type - when index expression is a slice and one of the slice elements wasn't recognized, it was running return from invalid_index_type immediately.
E.g. [1, 2, 3][x:"y"], where x is a variable of unknown type, is a real bug - "y" cannot be used as slice upper bound, but since x is not recognized, it's a variable and we cannot get its type, code never reached "y".
This PR is just using continue for this case instead of return, so those issues are recognized too.

Test Plan

Ran cargo test, updated snapshots.
Separated change in two commits - in first I just added a fixture and updated the snapshot (nothing is emitted - just new fixture appended to previous fixture context), in second I've made the change and updated snapshot.

@astral-sh-bot
astral-sh-bot Bot requested a review from ntBre July 19, 2026 19:07
@astral-sh-bot

astral-sh-bot Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@Andrej730
Andrej730 force-pushed the invalid-index-type-unrecog-bound branch from 1270c47 to 2fda272 Compare July 19, 2026 20:47

@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.

Nice, thank you!

Codex said that this was accidentally changed in #8064, which seems to be the case given that it was released in 0.1.4:

$ uvx [email protected] check --select RUF016 --isolated - <<EOF 
x = "x"
var = [1, 2, 3][x:"y"]
EOF
-:2:19: RUF016 Slice in indexed access to type `list` uses type `str` instead of an integer.
Found 1 error.
$ uvx [email protected] check --select RUF016 --isolated - <<EOF 
x = "x"
var = [1, 2, 3][x:"y"]
EOF
$

@ntBre ntBre added the bug Something isn't working label Jul 20, 2026
@ntBre ntBre changed the title invalid_index_type: fix missing check on unrecognized early bound [ruff] Fix missing check on unrecognized early bound (RUF016) Jul 20, 2026
@ntBre
ntBre merged commit cc42899 into astral-sh:main Jul 20, 2026
47 checks passed
@Andrej730
Andrej730 deleted the invalid-index-type-unrecog-bound branch July 20, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants