mypy返回模块'X'在django rest框架中没有属性'MyClass'

时间:2019-03-29 09:00:18

标签: django django-rest-framework mypy

我有以下django rest框架设置

app / models.py:

from django.db import models
class A(models.Model):
    x = models.CharField(max_length=8)

app / 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:错误:模块'app.models'没有属性'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

我该如何解决似乎仅与通过预提交挂钩运行有关的错误?

0 个答案:

没有答案