selwin / django-user_agents

A django package that allows easy identification of visitor's browser, OS and device information, including whether the visitor uses a mobile phone, tablet or a touch capable device.
MIT License
640 stars 104 forks source link

Type checking with mypy #39

Open caseydm opened 4 years ago

caseydm commented 4 years ago

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