-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Support all (or at least more) forms of the functional API for Enum creation #1127
Comments
There's already a much cleaner way to define enums if you have static enum labels, so I recommend you use that instead of these alternate forms. These alternate forms are generally only useful if your enum labels are dynamic. And in those cases, a static type checker won't be able to understand them anyway. We could theoretically handle a specific case where you're using a list expression with string literals (as opposed to a variable that contains a list or a list constructor call), but it would involve a bunch of special-case code. I don't think it's worth it. I'm going to close this as "won't fix", but other users can feel free to upvote or comment, and we might reconsider this decision in the future. |
I disagree. It's useful to specify an enum as a one-liner without having to worry about the values. |
data point: mypy considered this a high priority issue python/mypy#2306 If you're in strict mode pyright's errors are a bit harder to work around, but it might have only been high priority for mypy cause they error'd in default mode |
* change n^2 linear search to map this improves 260ms to 70ms on my test env. improvement will be even bigger for longer auto import list. * addressed PR feedback
Hoping pyright will also support the tuple/mapping syntax too! MyEnum = Enum('MyEnum', {'HA': 'ha', 'FOO': 'bar'}) |
…ings, a tuple of strings, a list of tuples, a tuple of tuples, and a map. This addresses #1127.
I've added support for the following Enum functional forms:
This will be included in the next release. |
This is addressed in pyright 1.1.304, which is now published. It will also be included in a future release of pylance. |
Is your feature request related to a problem? Please describe.
I'd like to use this form of Enum creation:
but it is currently not supported by pyright.
A full list of allowed forms can be found here: python/mypy#2306
Describe the solution you'd like
I'd like pyright to accept the above code and to know about the members
B.p
,B.q
andB.r
. This is the behavior thatmypy
has.Additional context
Pyright already supports this form:
but I think this is visually not as easy to parse.
The text was updated successfully, but these errors were encountered: