I am integrating mypy on a existing codebase(using django, drf frameworks).
Sample code in view.py:
from rest_framework.permissions import IsAdminUser, IsAuthenticatedOrReadOnly
@api_view()
@permission_classes([IsAuthenticatedOrReadOnly | IsAdminUser])
def listAbc(request):
queryset = ...
serializer = ...
return Response(serializer.data)
Result:
$ mypy
error: Unsupported left operand type for | ("Type[IsAuthenticatedOrReadOnly]")
Plugins used:
$ pip list | grep stubs
django-stubs 1.2.0
djangorestframework-stubs 1.0.0
mypy configuration file (mypy.ini):
[mypy]
plugins =
mypy_django_plugin.main, mypy_drf_plugin.main
;ignore_missing_imports = True
files=**/*.py
[mypy-*.migrations.*]
ignore_errors = True
[mypy.plugins.django-stubs]
django_settings_module = project.settings
Checked with both mypy (0.720 and 0.740).
What could be the issue here ? Since the operation '|' is not recognized by mypy, I suspect the metaclass BasePermissionMetaclass (containing the operations) is not added BasePermission during mypy evaluation. I assume just installing djangorestframework-stubs and configuring the same in mypy.ini is enough.