Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/ruff/RUF016.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,7 @@ def func():

# Should emit for invalid access using generator
var = [1, 2, 3][(x for x in ())]

# Should still emit for a later invalid bound, even if an earlier bound is unrecognized
x = "x"
var = [1, 2, 3][x:"y"]
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub(crate) fn invalid_index_type(checker: &Checker, expr: &ExprSubscript) {
{
for is_slice in [lower, upper, step].into_iter().flatten() {
let Some(is_slice_type) = CheckableExprType::try_from(is_slice) else {
return;
continue;
};
if is_slice_type.is_literal() {
// If the index is a slice, require integer or null bounds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,15 @@ RUF016 Indexed access to type `list` uses type `generator` instead of an integer
129 | # Should emit for invalid access using generator
130 | var = [1, 2, 3][(x for x in ())]
| ^^^^^^^^^^^^^^^
131 |
132 | # Should still emit for a later invalid bound, even if an earlier bound is unrecognized
|

RUF016 Slice in indexed access to type `list` uses type `str` instead of an integer
--> RUF016.py:134:19
|
132 | # Should still emit for a later invalid bound, even if an earlier bound is unrecognized
133 | x = "x"
134 | var = [1, 2, 3][x:"y"]
| ^^^
|
Loading