Skip to content

Commit 9bea80e

Browse files
tekknolagifacebook-github-bot
authored andcommitted
Allow assigning literals to Exact[int]
Reviewed By: carljm, wmeehan Differential Revision: D37863615 fbshipit-source-id: e75ef58c4738d8e10e73fd25685eaf5837381beb
1 parent 6260e06 commit 9bea80e

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

Lib/compiler/static/types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,8 @@ def get_generic_type(
657657
return concrete
658658

659659
def get_literal_type(self, base_type: Value, literal_value: object) -> Value:
660+
# Literals are always exact
661+
base_type = base_type.exact()
660662
key = (base_type, literal_value)
661663
if key not in self._literal_types:
662664
self._literal_types[key] = literal_type = base_type.make_literal(

Lib/test/test_compiler/test_static/annotated.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,9 @@ def test_exact_does_not_allow_literals(self) -> None:
192192
from typing import Annotated
193193
194194
x: Annotated[int, "Exact"] = 3
195+
reveal_type(x)
195196
"""
196-
# TODO(T113108364): This should be allowed.
197-
self.type_error(
198-
codestr, r"type mismatch: Literal\[3\] cannot be assigned to Exact\[int\]"
199-
)
197+
self.revealed_type(codestr, "Exact[int]")
200198

201199
def test_exact_final_type_error_on_subclass_assignment(self) -> None:
202200
codestr = """

0 commit comments

Comments
 (0)