我正在现有的代码库上集成mypy(使用django、drf框架)。你知道吗
中的示例代码视图.py地址:
from rest_framework.permissions import IsAdminUser, IsAuthenticatedOrReadOnly
@api_view()
@permission_classes([IsAuthenticatedOrReadOnly | IsAdminUser])
def listAbc(request):
queryset = ...
serializer = ...
return Response(serializer.data)
结果:
$ mypy
error: Unsupported left operand type for | ("Type[IsAuthenticatedOrReadOnly]")
使用的插件:
$ pip list | grep stubs
django-stubs 1.2.0
djangorestframework-stubs 1.0.0
mypy配置文件(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
用mypy(0.720和0.740)检查。你知道吗
有什么问题吗? 由于mypy无法识别操作“|”,我怀疑元类BasePermissionMetaclass(包含这些操作)在mypy求值期间没有添加BasePermission。我假设只是安装djangorestframework存根并在中配置相同的存根mypy.ini文件够了。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐