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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

RUF016 Slice in indexed access to type `list` uses type `float` instead of an integer
  --> RUF016.py:66:17
   |
64 | var = [1, 2, 3]["x":2]
65 | var = [1, 2, 3][f"x":2]
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 Slice in indexed access to type `list` uses type `set` instead of an integer
  --> RUF016.py:67:17
   |
65 | var = [1, 2, 3][f"x":2]
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]
69 | var = [1, 2, 3][{"x": x for x in range(2)}:2]
   |

RUF016 Slice in indexed access to type `list` uses type `set comprehension` instead of an integer
  --> RUF016.py:68:17
   |
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]
   |                 ^^^^^^^^^^^^^^^^^^^^^
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 Slice in indexed access to type `list` uses type `dict comprehension` instead of an integer
  --> RUF016.py:69:17
   |
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]
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
70 | var = [1, 2, 3][[x for x in range(2)]:2]
   |

RUF016 Slice in indexed access to type `list` uses type `list comprehension` instead of an integer
  --> RUF016.py:70:17
   |
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]
   |                 ^^^^^^^^^^^^^^^^^^^^^
71 |
72 | # Should emit for non-integer slice end
   |

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

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

RUF016 Slice in indexed access to type `list` uses type `float` instead of an integer
  --> RUF016.py:75:19
   |
73 | var = [1, 2, 3][0:"x"]
74 | var = [1, 2, 3][0:f"x"]
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 Slice in indexed access to type `list` uses type `set` instead of an integer
  --> RUF016.py:76:19
   |
74 | var = [1, 2, 3][0:f"x"]
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)}]
78 | var = [1, 2, 3][0:{"x": x for x in range(2)}]
   |

RUF016 Slice in indexed access to type `list` uses type `set comprehension` instead of an integer
  --> RUF016.py:77:19
   |
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)}]
   |                   ^^^^^^^^^^^^^^^^^^^^^
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 Slice in indexed access to type `list` uses type `dict comprehension` instead of an integer
  --> RUF016.py:78:19
   |
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)}]
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
79 | var = [1, 2, 3][0:[x for x in range(2)]]
   |

RUF016 Slice in indexed access to type `list` uses type `list comprehension` instead of an integer
  --> RUF016.py:79:19
   |
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)]]
   |                   ^^^^^^^^^^^^^^^^^^^^^
80 |
81 | # Should emit for non-integer slice step
   |

RUF016 Slice in indexed access to type `list` uses type `str` instead of an integer
  --> RUF016.py:82:21
   |
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"]
84 | var = [1, 2, 3][0:1:1.2]
   |

RUF016 Slice in indexed access to type `list` uses type `str` instead of an integer
  --> RUF016.py:83:21
   |
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"]
   |                     ^^^^
84 | var = [1, 2, 3][0:1:1.2]
85 | var = [1, 2, 3][0:1:{"x"}]
   |

RUF016 Slice in indexed access to type `list` uses type `float` instead of an integer
  --> RUF016.py:84:21
   |
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]
   |                     ^^^
85 | var = [1, 2, 3][0:1:{"x"}]
86 | var = [1, 2, 3][0:1:{x for x in range(2)}]
   |

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

RUF016 Slice in indexed access to type `list` uses type `list comprehension` instead of an integer
  --> RUF016.py:88:21
   |
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)]]
   |                     ^^^^^^^^^^^^^^^^^^^^^
89 |
90 | # Should emit for non-integer slice start and end; should emit twice with specific ranges
   |

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

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

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

RUF016 Indexed access to type `list` uses type `Template` instead of an integer or slice
   --> RUF016.py:124:14
    |
123 | # Should emit for invalid access using t-string
124 | var = [1, 2][t"x"]
    |              ^^^^
125 |
126 | # Should emit for invalid access using lambda
    |

RUF016 Indexed access to type `list` uses type `lambda` instead of an integer or slice
   --> RUF016.py:127:17
    |
126 | # Should emit for invalid access using lambda
127 | var = [1, 2, 3][lambda: 0]
    |                 ^^^^^^^^^
128 |
129 | # Should emit for invalid access using generator
    |

RUF016 Indexed access to type `list` uses type `generator` instead of an integer or slice
   --> RUF016.py:130:17
    |
129 | # Should emit for invalid access using generator
130 | var = [1, 2, 3][(x for x in ())]
    |                 ^^^^^^^^^^^^^^^
    |
