我有以下 django rest 框架设置
应用程序/模型.py:
from django.db import models
class A(models.Model):
x = models.CharField(max_length=8)
应用程序/serializer.py:
from .models import A
from rest_framework import serializers
class ASerializer(serializers.ModelSerializer):
class Meta:
model = A
fields = "__all__"
我已将 mypy 配置为使用以下设置作为预提交挂钩运行:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.670 # Use the sha / tag you want to point at
hooks:
- id: mypy
但是 mypy (0.67) 返回以下错误:serializer.py: error: Module 'app.models' has no attribute 'A'
如果我在为 django 和 django rest_framework 安装存根后在命令行上运行 mypy,则 mypy 运行正常并且没有报告错误:
mypy.ini
[mypy]
plugins = mypy_django_plugin.main, mypy_drf_plugin.main
pip install django-stubs
pip install djangorestframework-stubs
mypy app/serializers.py
我该如何解决这个似乎只与通过预提交挂钩运行有关的错误?