Skip to content

Commit

Permalink
DOC: Fixes Intelligent indexing example (#11973)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisKeefe committed Jan 12, 2022
1 parent 6c1eb5b commit 0bc040e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/source/literal_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ corresponding to some particular index, we can use Literal types like so:
# But what if we want the index to be a variable? Normally mypy won't
# know exactly what the index is and so will return a less precise type:
int_index = 1
int_index = 0
reveal_type(tup[int_index]) # Revealed type is "Union[str, float]"
# But if we use either Literal types or a Final int, we can gain back
# the precision we originally had:
lit_index: Literal[1] = 1
fin_index: Final = 1
lit_index: Literal[0] = 0
fin_index: Final = 0
reveal_type(tup[lit_index]) # Revealed type is "str"
reveal_type(tup[fin_index]) # Revealed type is "str"
Expand Down

0 comments on commit 0bc040e

Please sign in to comment.