typeddjango / djangorestframework-stubs

PEP-484 stubs for django-rest-framework
MIT License
454 stars 118 forks source link

False positive "metaclass conflict" error with GenericViewSet #692

Open realsuayip opened 2 weeks ago

realsuayip commented 2 weeks ago

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

https://github.com/python/mypy/issues/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.