Skip to content

disallow generic Enums and fix assigning Enum indexes #3140

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

Merged
merged 2 commits into from
Apr 7, 2017

Conversation

JelleZijlstra
Copy link
Member

Fixes #3137

Under some circumstances, Enum indexing was interpreted as creating a type alias. I fixed that bug by making it so that indexing an Enum typeinfo never creates an alias. Not the most elegant solution but I'm not sure there's a better one.

In the process, I discovered that mypy allows generic enums. I don't think a generic enum makes practical sense, and inheriting from both Enum and Generic[T] fails at runtime with a metaclass conflict. Therefore, this PR also disallows generic enums.

@ilevkivskyi
Copy link
Member

I think this is the correct fix. I just would add one more test to check that val = E[1] fails with a correct error ("Enum index should be a string ..."), otherwise LGTM.

@ilevkivskyi ilevkivskyi merged commit 745d300 into python:master Apr 7, 2017
@JelleZijlstra JelleZijlstra deleted the genericenum branch May 4, 2017 04:06
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

Successfully merging this pull request may close these issues.

Indexing Enum type objects fails sometimes
2 participants