basedmypy
basedmypy copied to clipboard
narrow literal types
a = "is this a joke"
reveal_type(a) # str
b: str
assert b == "is this a joke"
reveal_type(b) # str
it should also narrow in cases like this:
from typing import Literal
value: str
assert value == "asdf" # not sure about this because __eq__ can be overridden
assert value is "asdf" # but this one should definitely work
foo: Literal["asdf"] = value # error: Incompatible types in assignment (expression has type "str", variable has type "Literal['asdf']")