request.user has type of AUTH_USER_MODEL

This commit is contained in:
Maxim Kurnikov
2019-07-20 22:44:40 +03:00
parent 248504c25a
commit fa57fb0cbf
7 changed files with 43 additions and 6 deletions
+7 -2
View File
@@ -11,7 +11,7 @@ from mypy.types import Type as MypyType
from mypy_django_plugin.django.context import DjangoContext
from mypy_django_plugin.lib import fullnames, helpers
from mypy_django_plugin.transformers import fields, forms, init_create, querysets, settings, meta
from mypy_django_plugin.transformers import fields, forms, init_create, querysets, settings, meta, request
from mypy_django_plugin.transformers.models import process_model_class
@@ -109,7 +109,7 @@ class NewSemanalDjangoPlugin(Plugin):
# for `get_user_model()`
if self.django_context.settings:
if file.fullname() == 'django.contrib.auth':
if (file.fullname() == 'django.contrib.auth') or (file.fullname() in {'django.http', 'django.http.request'}):
auth_user_model_name = self.django_context.settings.AUTH_USER_MODEL
try:
auth_user_module = self.django_context.apps_registry.get_model(auth_user_model_name).__module__
@@ -204,6 +204,11 @@ class NewSemanalDjangoPlugin(Plugin):
return partial(settings.get_type_of_settings_attribute,
django_context=self.django_context)
info = self._get_typeinfo_or_none(class_name)
if info and info.has_base(fullnames.HTTPREQUEST_CLASS_FULLNAME):
return partial(request.set_auth_user_model_as_type_for_request_user, django_context=self.django_context)
# def get_type_analyze_hook(self, fullname: str
# ( ):
# info = self._get_typeinfo_or_none(fullname)