---
source: crates/ruff_linter/src/rules/ruff/mod.rs
---
RUF016.py:20:13: RUF016 Indexed access to type `str` uses type `str` instead of an integer or slice
   |
19 | # Should emit for invalid access on strings
20 | var = "abc"["x"]
   |             ^^^ RUF016
21 | var = f"abc"["x"]
   |

RUF016.py:21:14: RUF016 Indexed access to type `str` uses type `str` instead of an integer or slice
   |
19 | # Should emit for invalid access on strings
20 | var = "abc"["x"]
21 | var = f"abc"["x"]
   |              ^^^ RUF016
22 | 
23 | # Should emit for invalid access on bytes
   |

RUF016.py:24:14: RUF016 Indexed access to type `bytes` uses type `str` instead of an integer or slice
   |
23 | # Should emit for invalid access on bytes
24 | var = b"abc"["x"]
   |              ^^^ RUF016
25 | 
26 | # Should emit for invalid access on lists and tuples
   |

RUF016.py:27:17: RUF016 Indexed access to type `list` uses type `str` instead of an integer or slice
   |
26 | # Should emit for invalid access on lists and tuples
27 | var = [1, 2, 3]["x"]
   |                 ^^^ RUF016
28 | var = (1, 2, 3)["x"]
   |

RUF016.py:28:17: RUF016 Indexed access to type `tuple` uses type `str` instead of an integer or slice
   |
26 | # Should emit for invalid access on lists and tuples
27 | var = [1, 2, 3]["x"]
28 | var = (1, 2, 3)["x"]
   |                 ^^^ RUF016
29 | 
30 | # Should emit for invalid access on list comprehensions
   |

RUF016.py:31:30: RUF016 Indexed access to type `list comprehension` uses type `str` instead of an integer or slice
   |
30 | # Should emit for invalid access on list comprehensions
31 | var = [x for x in range(10)]["x"]
   |                              ^^^ RUF016
32 | 
33 | # Should emit for invalid access using tuple
   |

RUF016.py:34:13: RUF016 Indexed access to type `str` uses type `tuple` instead of an integer or slice
   |
33 | # Should emit for invalid access using tuple
34 | var = "abc"[1, 2]
   |             ^^^^ RUF016
35 | 
36 | # Should emit for invalid access using string
   |

RUF016.py:37:14: RUF016 Indexed access to type `list` uses type `str` instead of an integer or slice
   |
36 | # Should emit for invalid access using string
37 | var = [1, 2]["x"]
   |              ^^^ RUF016
38 | 
39 | # Should emit for invalid access using float
   |

RUF016.py:40:14: RUF016 Indexed access to type `list` uses type `float` instead of an integer or slice
   |
39 | # Should emit for invalid access using float
40 | var = [1, 2][0.25]
   |              ^^^^ RUF016
41 | 
42 | # Should emit for invalid access using dict
   |

RUF016.py:43:14: RUF016 Indexed access to type `list` uses type `dict` instead of an integer or slice
   |
42 | # Should emit for invalid access using dict
43 | var = [1, 2][{"x": "y"}]
   |              ^^^^^^^^^^ RUF016
44 | 
45 | # Should emit for invalid access using dict comp
   |

RUF016.py:46:14: RUF016 Indexed access to type `list` uses type `dict comprehension` instead of an integer or slice
   |
45 | # Should emit for invalid access using dict comp
46 | var = [1, 2][{x: "y" for x in range(2)}]
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF016
47 | 
48 | # Should emit for invalid access using list 
   |

RUF016.py:49:14: RUF016 Indexed access to type `list` uses type `tuple` instead of an integer or slice
   |
48 | # Should emit for invalid access using list 
49 | var = [1, 2][2, 3]
   |              ^^^^ RUF016
50 | 
51 | # Should emit for invalid access using list comp
   |

RUF016.py:52:14: RUF016 Indexed access to type `list` uses type `list comprehension` instead of an integer or slice
   |
51 | # Should emit for invalid access using list comp
52 | var = [1, 2][[x for x in range(2)]]
   |              ^^^^^^^^^^^^^^^^^^^^^ RUF016
53 | 
54 | # Should emit on invalid access using set
   |

RUF016.py:55:14: RUF016 Indexed access to type `list` uses type `set` instead of an integer or slice
   |
54 | # Should emit on invalid access using set
55 | var = [1, 2][{"x", "y"}]
   |              ^^^^^^^^^^ RUF016
56 | 
57 | # Should emit on invalid access using set comp
   |

RUF016.py:58:14: RUF016 Indexed access to type `list` uses type `set comprehension` instead of an integer or slice
   |
57 | # Should emit on invalid access using set comp
58 | var = [1, 2][{x for x in range(2)}]
   |              ^^^^^^^^^^^^^^^^^^^^^ RUF016
59 | 
60 | # Should emit on invalid access using bytes
   |

RUF016.py:61:14: RUF016 Indexed access to type `list` uses type `bytes` instead of an integer or slice
   |
60 | # Should emit on invalid access using bytes
61 | var = [1, 2][b"x"]
   |              ^^^^ RUF016
62 | 
63 | # Should emit for non-integer slice start
   |

RUF016.py:64:17: RUF016 Slice in indexed access to type `list` uses type `str` instead of an integer
   |
63 | # Should emit for non-integer slice start
64 | var = [1, 2, 3]["x":2]
   |                 ^^^ RUF016
65 | var = [1, 2, 3][f"x":2]
66 | var = [1, 2, 3][1.2:2]
   |

RUF016.py:65:17: RUF016 Slice in indexed access to type `list` uses type `str` instead of an integer
   |
63 | # Should emit for non-integer slice start
64 | var = [1, 2, 3]["x":2]
65 | var = [1, 2, 3][f"x":2]
   |                 ^^^^ RUF016
66 | var = [1, 2, 3][1.2:2]
67 | var = [1, 2, 3][{"x"}:2]
   |

RUF016.py:66:17: RUF016 Slice in indexed access to type `list` uses type `float` instead of an integer
   |
64 | var = [1, 2, 3]["x":2]
65 | var = [1, 2, 3][f"x":2]
66 | var = [1, 2, 3][1.2:2]
   |                 ^^^ RUF016
67 | var = [1, 2, 3][{"x"}:2]
68 | var = [1, 2, 3][{x for x in range(2)}:2]
   |

RUF016.py:67:17: RUF016 Slice in indexed access to type `list` uses type `set` instead of an integer
   |
65 | var = [1, 2, 3][f"x":2]
66 | var = [1, 2, 3][1.2:2]
67 | var = [1, 2, 3][{"x"}:2]
   |                 ^^^^^ RUF016
68 | var = [1, 2, 3][{x for x in range(2)}:2]
69 | var = [1, 2, 3][{"x": x for x in range(2)}:2]
   |

RUF016.py:68:17: RUF016 Slice in indexed access to type `list` uses type `set comprehension` instead of an integer
   |
66 | var = [1, 2, 3][1.2:2]
67 | var = [1, 2, 3][{"x"}:2]
68 | var = [1, 2, 3][{x for x in range(2)}:2]
   |                 ^^^^^^^^^^^^^^^^^^^^^ RUF016
69 | var = [1, 2, 3][{"x": x for x in range(2)}:2]
70 | var = [1, 2, 3][[x for x in range(2)]:2]
   |

RUF016.py:69:17: RUF016 Slice in indexed access to type `list` uses type `dict comprehension` instead of an integer
   |
67 | var = [1, 2, 3][{"x"}:2]
68 | var = [1, 2, 3][{x for x in range(2)}:2]
69 | var = [1, 2, 3][{"x": x for x in range(2)}:2]
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF016
70 | var = [1, 2, 3][[x for x in range(2)]:2]
   |

RUF016.py:70:17: RUF016 Slice in indexed access to type `list` uses type `list comprehension` instead of an integer
   |
68 | var = [1, 2, 3][{x for x in range(2)}:2]
69 | var = [1, 2, 3][{"x": x for x in range(2)}:2]
70 | var = [1, 2, 3][[x for x in range(2)]:2]
   |                 ^^^^^^^^^^^^^^^^^^^^^ RUF016
71 | 
72 | # Should emit for non-integer slice end
   |

RUF016.py:73:19: RUF016 Slice in indexed access to type `list` uses type `str` instead of an integer
   |
72 | # Should emit for non-integer slice end
73 | var = [1, 2, 3][0:"x"]
   |                   ^^^ RUF016
74 | var = [1, 2, 3][0:f"x"]
75 | var = [1, 2, 3][0:1.2]
   |

RUF016.py:74:19: RUF016 Slice in indexed access to type `list` uses type `str` instead of an integer
   |
72 | # Should emit for non-integer slice end
73 | var = [1, 2, 3][0:"x"]
74 | var = [1, 2, 3][0:f"x"]
   |                   ^^^^ RUF016
75 | var = [1, 2, 3][0:1.2]
76 | var = [1, 2, 3][0:{"x"}]
   |

RUF016.py:75:19: RUF016 Slice in indexed access to type `list` uses type `float` instead of an integer
   |
73 | var = [1, 2, 3][0:"x"]
74 | var = [1, 2, 3][0:f"x"]
75 | var = [1, 2, 3][0:1.2]
   |                   ^^^ RUF016
76 | var = [1, 2, 3][0:{"x"}]
77 | var = [1, 2, 3][0:{x for x in range(2)}]
   |

RUF016.py:76:19: RUF016 Slice in indexed access to type `list` uses type `set` instead of an integer
   |
74 | var = [1, 2, 3][0:f"x"]
75 | var = [1, 2, 3][0:1.2]
76 | var = [1, 2, 3][0:{"x"}]
   |                   ^^^^^ RUF016
77 | var = [1, 2, 3][0:{x for x in range(2)}]
78 | var = [1, 2, 3][0:{"x": x for x in range(2)}]
   |

RUF016.py:77:19: RUF016 Slice in indexed access to type `list` uses type `set comprehension` instead of an integer
   |
75 | var = [1, 2, 3][0:1.2]
76 | var = [1, 2, 3][0:{"x"}]
77 | var = [1, 2, 3][0:{x for x in range(2)}]
   |                   ^^^^^^^^^^^^^^^^^^^^^ RUF016
78 | var = [1, 2, 3][0:{"x": x for x in range(2)}]
79 | var = [1, 2, 3][0:[x for x in range(2)]]
   |

RUF016.py:78:19: RUF016 Slice in indexed access to type `list` uses type `dict comprehension` instead of an integer
   |
76 | var = [1, 2, 3][0:{"x"}]
77 | var = [1, 2, 3][0:{x for x in range(2)}]
78 | var = [1, 2, 3][0:{"x": x for x in range(2)}]
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF016
79 | var = [1, 2, 3][0:[x for x in range(2)]]
   |

RUF016.py:79:19: RUF016 Slice in indexed access to type `list` uses type `list comprehension` instead of an integer
   |
77 | var = [1, 2, 3][0:{x for x in range(2)}]
78 | var = [1, 2, 3][0:{"x": x for x in range(2)}]
79 | var = [1, 2, 3][0:[x for x in range(2)]]
   |                   ^^^^^^^^^^^^^^^^^^^^^ RUF016
80 | 
81 | # Should emit for non-integer slice step
   |

RUF016.py:82:21: RUF016 Slice in indexed access to type `list` uses type `str` instead of an integer
   |
81 | # Should emit for non-integer slice step
82 | var = [1, 2, 3][0:1:"x"]
   |                     ^^^ RUF016
83 | var = [1, 2, 3][0:1:f"x"]
84 | var = [1, 2, 3][0:1:1.2]
   |

RUF016.py:83:21: RUF016 Slice in indexed access to type `list` uses type `str` instead of an integer
   |
81 | # Should emit for non-integer slice step
82 | var = [1, 2, 3][0:1:"x"]
83 | var = [1, 2, 3][0:1:f"x"]
   |                     ^^^^ RUF016
84 | var = [1, 2, 3][0:1:1.2]
85 | var = [1, 2, 3][0:1:{"x"}]
   |

RUF016.py:84:21: RUF016 Slice in indexed access to type `list` uses type `float` instead of an integer
   |
82 | var = [1, 2, 3][0:1:"x"]
83 | var = [1, 2, 3][0:1:f"x"]
84 | var = [1, 2, 3][0:1:1.2]
   |                     ^^^ RUF016
85 | var = [1, 2, 3][0:1:{"x"}]
86 | var = [1, 2, 3][0:1:{x for x in range(2)}]
   |

RUF016.py:85:21: RUF016 Slice in indexed access to type `list` uses type `set` instead of an integer
   |
83 | var = [1, 2, 3][0:1:f"x"]
84 | var = [1, 2, 3][0:1:1.2]
85 | var = [1, 2, 3][0:1:{"x"}]
   |                     ^^^^^ RUF016
86 | var = [1, 2, 3][0:1:{x for x in range(2)}]
87 | var = [1, 2, 3][0:1:{"x": x for x in range(2)}]
   |

RUF016.py:86:21: RUF016 Slice in indexed access to type `list` uses type `set comprehension` instead of an integer
   |
84 | var = [1, 2, 3][0:1:1.2]
85 | var = [1, 2, 3][0:1:{"x"}]
86 | var = [1, 2, 3][0:1:{x for x in range(2)}]
   |                     ^^^^^^^^^^^^^^^^^^^^^ RUF016
87 | var = [1, 2, 3][0:1:{"x": x for x in range(2)}]
88 | var = [1, 2, 3][0:1:[x for x in range(2)]]
   |

RUF016.py:87:21: RUF016 Slice in indexed access to type `list` uses type `dict comprehension` instead of an integer
   |
85 | var = [1, 2, 3][0:1:{"x"}]
86 | var = [1, 2, 3][0:1:{x for x in range(2)}]
87 | var = [1, 2, 3][0:1:{"x": x for x in range(2)}]
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF016
88 | var = [1, 2, 3][0:1:[x for x in range(2)]]
   |

RUF016.py:88:21: RUF016 Slice in indexed access to type `list` uses type `list comprehension` instead of an integer
   |
86 | var = [1, 2, 3][0:1:{x for x in range(2)}]
87 | var = [1, 2, 3][0:1:{"x": x for x in range(2)}]
88 | var = [1, 2, 3][0:1:[x for x in range(2)]]
   |                     ^^^^^^^^^^^^^^^^^^^^^ RUF016
89 | 
90 | # Should emit for non-integer slice start and end; should emit twice with specific ranges
   |

RUF016.py:91:17: RUF016 Slice in indexed access to type `list` uses type `str` instead of an integer
   |
90 | # Should emit for non-integer slice start and end; should emit twice with specific ranges
91 | var = [1, 2, 3]["x":"y"]
   |                 ^^^ RUF016
92 | 
93 | # Should emit once for repeated invalid access
   |

RUF016.py:91:21: RUF016 Slice in indexed access to type `list` uses type `str` instead of an integer
   |
90 | # Should emit for non-integer slice start and end; should emit twice with specific ranges
91 | var = [1, 2, 3]["x":"y"]
   |                     ^^^ RUF016
92 | 
93 | # Should emit once for repeated invalid access
   |

RUF016.py:94:17: RUF016 Indexed access to type `list` uses type `str` instead of an integer or slice
   |
93 | # Should emit once for repeated invalid access
94 | var = [1, 2, 3]["x"]["y"]["z"]
   |                 ^^^ RUF016
95 | 
96 | # Cannot emit on invalid access using variable in index
   |


