Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to annotate Django view's methods?

I'd like to use Python type hints in my Django project. What's the proper way to annotate get/post methods of a simple class-based view in Django?

I've searched the Django code itself but it doesn't seem to contain any type hints.

like image 894
planetp Avatar asked May 18 '17 20:05

planetp


1 Answers

There exists this repository which may interest you: https://github.com/machinalis/mypy-django
which will allow you to use annotations like so:

def get(self, request: HttpRequest, question_id: str) -> HttpResponse:
like image 147
John Moutafis Avatar answered Oct 19 '22 22:10

John Moutafis