selwin/django-user_agents

Type checking with mypy

Opened this issue · 0 comments

I'm using mypy with the Django plugin. When I reference request.user_agent with a function like this:

from django.core.handlers.wsgi import WSGIRequest

def get_application(request: WSGIRequest) -> Application:
    if request.user_agent.is_mobile:
      pass

mypy complains:

error: "WSGIRequest" has no attribute "user_agent"

Is there a way to resolve this error? All I can think of right now is to ignore it with # type: ignore.

Here is the mypy config file for reference:

[mypy]
ignore_missing_imports = True

plugins =
    mypy_django_plugin.main

[mypy.plugins.django-stubs]
django_settings_module = myapp.settings.base