pyre-check
pyre-check copied to clipboard
Pyre infers set-of-literals as set[str] rather than set[MyLiteral]
Pyre Bug
Bug description
I expected the following script to pass type checking:
import typing as t
Foo = t.Literal["foo-1", "foo-2"]
FOO_1: Foo = "foo-1"
FOO_2: Foo = "foo-2"
def use_set_of_foos(v: set[Foo]):
print(v)
# Typecheck fails here, because {FOO_1} is inferred to be set[str] rather than set[Foo]
use_set_of_foos({FOO_1})
Reproduction steps
See script above.
Expected behavior
I expected this to pass type checking
Logs Please include any relevant logs here:
ƛ Found 1 type error!
repro.py:13:16 Incompatible parameter type [6]: In call `use_set_of_foos`, for 1st positional argument, expected `Set[Union[typing_extensions.Literal['foo-1'], typing_extensions.Literal['foo-2']]]` but got `Set[str]`.
Hi! Thanks for the report. We are currently tracking improvements to expression-level type inference which would solve your problem. I'll add this to the set of examples.