[ruff] Fix missing check on unrecognized early bound (RUF016) - #26986
Merged
ntBre merged 2 commits intoJul 20, 2026
Merged
Conversation
|
Andrej730
force-pushed
the
invalid-index-type-unrecog-bound
branch
from
July 19, 2026 20:47
1270c47 to
2fda272
Compare
ntBre
approved these changes
Jul 20, 2026
ntBre
left a comment
Contributor
There was a problem hiding this comment.
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
$ruff] Fix missing check on unrecognized early bound (RUF016)
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
Noticed a bug in
invalid_index_type- when index expression is a slice and one of the slice elements wasn't recognized, it was runningreturnfrominvalid_index_typeimmediately.E.g.
[1, 2, 3][x:"y"], wherexis a variable of unknown type, is a real bug -"y"cannot be used as slice upper bound, but sincexis not recognized, it's a variable and we cannot get its type, code never reached"y".This PR is just using
continuefor this case instead ofreturn, 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.