Skip to content

False positive "metaclass conflict" error with GenericViewSet #692

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

Open
realsuayip opened this issue Nov 6, 2024 · 1 comment
Open

False positive "metaclass conflict" error with GenericViewSet #692

realsuayip opened this issue Nov 6, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@realsuayip
Copy link
Contributor

When using a custom metaclass with GenericViewSet will create "metaclass conflict" error. This seems to be due to some issue in mypy:

python/mypy#15040

GenericViewSet uses UsesQuerySet which is a Protocol, whose metaclass is ABCMeta, but during runtime type(GenericViewSet) is actually type

Using ABCMeta as base in custom metaclass fixes the issue, which is mostly fine although not entirely "correct".

I guess using protocols is more helpful than just satisfying an edge metaclass case. There seems to be some work in progress in mypy that might fix this issue, in the meantime, I wanted to open this issue here so that other people could see the cause & possible fix.

@realsuayip realsuayip added the bug Something isn't working label Nov 6, 2024
@craigds
Copy link

craigds commented Jan 24, 2025

Any use of GenericAPIView with a custom metaclass also hits this issue. Minimal repro is:

from rest_framework.generics import GenericAPIView


class MyMeta(type): ...


class MyView(GenericAPIView, metaclass=MyMeta): ...

Which results in:

foo.py:7: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants