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

Mypy doesn't recognize metaclass implementing __getitem__ #1771

Closed
sangsta opened this issue Jun 29, 2016 · 2 comments
Closed

Mypy doesn't recognize metaclass implementing __getitem__ #1771

sangsta opened this issue Jun 29, 2016 · 2 comments

Comments

@sangsta
Copy link

sangsta commented Jun 29, 2016

Suppose we have an Enum called MyEnum, and we try something like MyEnum["foo"], mypy will give us an error Value of type "MyEnum" is not indexable. We believe this is because mypy has trouble recognizing when a metaclass implements __getitem__.

A workaround is to do getattr(MyEnum, "foo"), but it'd be nice to have an actual fix.

@gvanrossum
Copy link
Member

Oh, it looks like this already exists in the tracker: #741. I'll have to close this as a duplicate.

@gvanrossum
Copy link
Member

Reopening this, since there's an extra wrinkle specifically for __getitem__ -- because X[Y] is used as generic type parameterization, even with @elazarg's fix (#2475) the metaclass's __getitem__ is not honored.

@gvanrossum gvanrossum reopened this Feb 6, 2017
gvanrossum pushed a commit that referenced this issue Feb 12, 2017
…#2827)

Fix #1771. (Seems to be much simpler than I thought)

In particular, this will allow removing some special-casing for enum (#2812).

Related to #1381.
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

No branches or pull requests

2 participants