Is there anyway to make this work
from typing import Literal
def foo(bar: Literal["bar"]) -> Literal["foo"]:
foo = "foo"
return foo
bar = "bar"
foo(bar)
Here are the errors
foo.py:4: error: Incompatible return value type (got "str", expected "Literal['foo']")
foo.py:8: error: Argument 1 to "foo" has incompatible type "str"; expected "Literal['bar']"
Is pretty obvious that foo variable and bar are literals because they are assigned to literals, so this is safe, but mypy seems to not track this. Is there anything that I'm missing?