-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Make enum values final #11919
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
Labels
Comments
Some experimentation shows that commenting out |
joey-laminar
added a commit
to joey-laminar/mypy
that referenced
this issue
Jan 10, 2022
This fix allows using enum values in place of literals. For example: ``` def is_a(a: Literal["a"]): return None class MyStr(Enum): a = "a" b = "b" is_a(MyStr.a.value) ``` Currently this fails with ``` error: Argument 1 to "is_a" has incompatible type "str"; expected "Literal['a']" ``` The fix itself is simple - the special casing of final status for enums was being called too late to have an effect. Moving the function call up solves the problem.
JelleZijlstra
pushed a commit
that referenced
this issue
Jan 10, 2022
This fix allows using enum values in place of literals. For example: ``` def is_a(a: Literal["a"]): return None class MyStr(Enum): a = "a" b = "b" is_a(MyStr.a.value) ``` Currently this fails with ``` error: Argument 1 to "is_a" has incompatible type "str"; expected "Literal['a']" ``` The fix itself is simple - the special casing of final status for enums was being called too late to have an effect. Moving the function call up solves the problem. Fixes #11919
tushar-deepsource
pushed a commit
to DeepSourceCorp/mypy
that referenced
this issue
Jan 20, 2022
This fix allows using enum values in place of literals. For example: ``` def is_a(a: Literal["a"]): return None class MyStr(Enum): a = "a" b = "b" is_a(MyStr.a.value) ``` Currently this fails with ``` error: Argument 1 to "is_a" has incompatible type "str"; expected "Literal['a']" ``` The fix itself is simple - the special casing of final status for enums was being called too late to have an effect. Moving the function call up solves the problem. Fixes python#11919
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#10852 made it so that boolean values are correctly identified as Literals in an enum. Other values seem to not be:
Results in:
Expected result:
The enum members themselves (MyInt.a) are correctly identified as final, but their values should be as well
The text was updated successfully, but these errors were encountered: