Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pyre infers set-of-literals as set[str] rather than set[MyLiteral] #783

Open
jakewins opened this issue Aug 23, 2023 · 1 comment
Open

Comments

@jakewins
Copy link

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]`.

rage.log

@kinto0
Copy link
Contributor

kinto0 commented Aug 23, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants