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

View File

@@ -15,9 +15,6 @@ def get_referred_to_model_fullname(ctx: FunctionContext, django_context: DjangoC
return to_arg_type.ret_type.type.fullname()
outer_model_info = ctx.api.scope.active_class()
# if not outer_model_info or not outer_model_info.has_base(fullnames.MODEL_CLASS_FULLNAME):
# # not inside models.Model class
# return None
assert isinstance(outer_model_info, TypeInfo)
to_arg_expr = helpers.get_call_argument_by_name(ctx, 'to')

View File

@@ -0,0 +1,15 @@
from mypy.plugin import AttributeContext
from mypy.types import Instance, Type as MypyType
from mypy_django_plugin.django.context import DjangoContext
from mypy_django_plugin.lib import helpers
def set_auth_user_model_as_type_for_request_user(ctx: AttributeContext, django_context: DjangoContext) -> MypyType:
auth_user_model = django_context.settings.AUTH_USER_MODEL
model_cls = django_context.apps_registry.get_model(auth_user_model)
model_info = helpers.lookup_class_typeinfo(ctx.api, model_cls)
if model_info is None:
return ctx.default_attr_type
return Instance(model_info, [])