Django Mypy树桩
emil-fixed-django-stubs的Python项目详细描述
Django框架的PEP484存根
这个包包含类型stubs和mypy插件,为django框架提供更精确的静态类型和类型推断。django使用了一些python“魔术”,这使得一些代码模式的精确类型成为问题。这就是为什么我们需要在stub中附带mypy插件。最后一个目标是能够获得最常见模式的精确类型。
支持Python3.6/3.7和Django 2.1.x系列。
可以在django的早期版本上运行,但预计会出现一些缺少导入警告的情况。
安装
pip install django-stubs
要让mypy知道这个插件,您需要添加
[mypy]
plugins =
mypy_django_plugin.main
在您的mypy.ini
文件中。
配置
要指定配置文件,请使用配置文件的路径设置MYPY_DJANGO_CONFIG
环境变量。默认值是./mypy_django.ini
配置文件格式(.ini):
[mypy_django_plugin]
# specify settings module to use for django.conf.settings, this setting
# could also be specified with DJANGO_SETTINGS_MODULE environment variable
# (it also takes priority over config file)
django_settings = mysettings.local
# if True, all unknown settings in django.conf.settings will fallback to Any,
# specify it if your settings are loaded dynamically to avoid false positives
ignore_missing_settings = True
# if True, unknown attributes on Model instances won't produce errors
ignore_missing_model_attributes = True
获取帮助
我们这里有吉特https://gitter.im/mypy-django/Lobby。
如果你认为你有更一般的打字问题,请参考https://github.com/python/mypy和他们的gitter。