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

Support enum square bracket notation #6135

Open
oyvinev opened this issue Jan 3, 2019 · 1 comment
Open

Support enum square bracket notation #6135

oyvinev opened this issue Jan 3, 2019 · 1 comment

Comments

@oyvinev
Copy link

oyvinev commented Jan 3, 2019

Enums can not always be accessed with .-notation, like in the example below.

import enum
import operator

OperatorEnum = enum.Enum(
    "OperatorEnum",
    {"==": operator.eq, ">=": operator.ge, "<=": operator.le, ">": operator.gt, "<": operator.lt},
)

OperatorEnum["foo"]  # pass, but should throw an error?
OperatorEnum.foo  # Fails

It would be great if OperatorEnum["foo"] is caught by mypy.

@ilevkivskyi ilevkivskyi added feature priority-1-normal topic-plugins The plugin API and ideas for new plugins labels Jan 3, 2019
@ilevkivskyi
Copy link
Member

Yes, this can be implemented using a plugin similar to how we do this for TypedDict.

There is a question however: what is the value of this pattern as compared to just using a dictionary?
It seems to me it is not very common, so on the second thought this looks like relatively low priority.

(Also note, you should use the same name for enum as in the l.h.s., I edited your post accordingly.)

@AlexWaygood AlexWaygood added topic-enum and removed topic-plugins The plugin API and ideas for new plugins labels Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants