You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
Sorry to dig this up after years, but it seems the issue was never really resolved besides printing the correct type in reveal_type().
I opened a new issue with details: #15107
I spent quite some time struggling to get custom generics to work in mypy, because this issue and the associated PR made me believe the feature is implemented.
To anyone in the same situation: Using custom generics via metaclass __getitem__ is not supported in mypy at the time being.
Activity
gvanrossum commentedon Jun 29, 2016
Oh, it looks like this already exists in the tracker: #741. I'll have to close this as a duplicate.
gvanrossum commentedon Feb 6, 2017
Reopening this, since there's an extra wrinkle specifically for
__getitem__-- becauseX[Y]is used as generic type parameterization, even with @elazarg's fix (#2475) the metaclass's__getitem__is not honored.Allow using __getitem__ defined in metaclasses of non-generic classes (…
raphCode commentedon Apr 27, 2023
Sorry to dig this up after years, but it seems the issue was never really resolved besides printing the correct type in
reveal_type().I opened a new issue with details: #15107
I spent quite some time struggling to get custom generics to work in mypy, because this issue and the associated PR made me believe the feature is implemented.
To anyone in the same situation:
Using custom generics via metaclass
__getitem__is not supported in mypy at the time being.