Skip to content

Commit

Permalink
Allow assigning literals to Exact[int]
Browse files Browse the repository at this point in the history
Reviewed By: carljm, wmeehan

Differential Revision: D37863615

fbshipit-source-id: e75ef58c4738d8e10e73fd25685eaf5837381beb
  • Loading branch information
tekknolagi authored and facebook-github-bot committed Sep 16, 2022
1 parent 6260e06 commit 9bea80e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Lib/compiler/static/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ def get_generic_type(
return concrete

def get_literal_type(self, base_type: Value, literal_value: object) -> Value:
# Literals are always exact
base_type = base_type.exact()
key = (base_type, literal_value)
if key not in self._literal_types:
self._literal_types[key] = literal_type = base_type.make_literal(
Expand Down
6 changes: 2 additions & 4 deletions Lib/test/test_compiler/test_static/annotated.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,9 @@ def test_exact_does_not_allow_literals(self) -> None:
from typing import Annotated
x: Annotated[int, "Exact"] = 3
reveal_type(x)
"""
# TODO(T113108364): This should be allowed.
self.type_error(
codestr, r"type mismatch: Literal\[3\] cannot be assigned to Exact\[int\]"
)
self.revealed_type(codestr, "Exact[int]")

def test_exact_final_type_error_on_subclass_assignment(self) -> None:
codestr = """
Expand Down

0 comments on commit 9bea80e

Please sign in to comment.