-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Singleton as enum doesn't work as expected #7279
Comments
You'll need to annotate Without it, mypy thinks that it's possible for |
Gotcha. I have what I need then, thank you! |
I wonder if we should special case this in mypy. @Michael0x2a What do you think about this? |
Yeah, I think special-casing could be reasonable, though probably it's not a big priority given that there's an easy workaround. Actually, now that I'm thinking about it, I wonder if it might be as easy as just adding another case to the |
Hi @Michael0x2a sorry for the late answer, was in vacation :). |
This PR adds supports for singleton types in unions using `Enum`s as described in [PEP 484][0] (without using `Final`). As suggested by @Michael0x2a in [the corresponding issue][1], adding another case to the `is_singleton_type` and `coerce_to_literal`functions allows mypy to recognize an `Enum` with 1 value as a singleton type. Fixes #7279 [0]: https://www.python.org/dev/peps/pep-0484/#support-for-singleton-types-in-unions [1]: #7279 (comment)
Hello,
Based on the tag in the commit e818a96 that is the merge commit of #7000, that is declared to fix #1803, the singleton scenario as described in https://www.python.org/dev/peps/pep-0484/#support-for-singleton-types-in-unions should be supported in 0.720.
However, it's still not the case:
does:
Have I misunderstood something?
Thank you!
The text was updated successfully, but these errors were encountered: