I have the following Django view:
@login_required
def view(request: HttpRequest) -> HttpResponse:
if not request.user.some_attribute:
return redirect("somewhere")
return render(request, "template_name")
and a custom User model that has an attribute some_attribute.
I use mypy to enforce type checking, with this mypy.ini:
[mypy]
ignore_missing_imports = True
plugins = mypy_django_plugin.main
[mypy.plugins.django-stubs]
django_settings_module = [PROJECT NAME].settings
However, mypy errors with the following:
Item "AnonymousUser" of "Union[User, AnonymousUser]" has no attribute "some_attribute"
which makes sense because an anonymous user wouldn't have that attribute, but I have a login_required decorator, making AnonymousUsers impossible (it would be a User).
How do I tell mypy to ignore this, without using # type: ignore?