Skip to content

Commit 0bc040e

Browse files
authored
DOC: Fixes Intelligent indexing example (#11973)
1 parent 6c1eb5b commit 0bc040e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

docs/source/literal_types.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,13 @@ corresponding to some particular index, we can use Literal types like so:
186186
187187
# But what if we want the index to be a variable? Normally mypy won't
188188
# know exactly what the index is and so will return a less precise type:
189-
int_index = 1
189+
int_index = 0
190190
reveal_type(tup[int_index]) # Revealed type is "Union[str, float]"
191191
192192
# But if we use either Literal types or a Final int, we can gain back
193193
# the precision we originally had:
194-
lit_index: Literal[1] = 1
195-
fin_index: Final = 1
194+
lit_index: Literal[0] = 0
195+
fin_index: Final = 0
196196
reveal_type(tup[lit_index]) # Revealed type is "str"
197197
reveal_type(tup[fin_index]) # Revealed type is "str"
198198

0 commit comments

Comments
 (0)