Hi guys.
Lets discuss about this
ticket
I think we need create new tag in template language to annotate context variable types. Something like
PEP 484 but on templates.
As in pep 484 main goal is provide easier static analysis, potential error checking and improve IDEs and editors support.
We can do this with new small tag. Something like:
@register.simpletag(name='var')
def type_hint(variable,variable_type_string: str) -> None:
pass
Then we can annotate variable in template:
{% var request 'django.http.HttpResponse' %} %}
or
{% var is_paginated 'bool' %}
or
{% var user_or_none 'typing.Union[None, django.contrib.auth.models.User]' %}
maybe
{% var user_or_none 'typing.Union[None, django.conf.settings.AUTH_USER_MODEL]' %}
Main idea is add this template to django default tags, not third part application.
Then IDE, editor plugins, and analysis tools can build support, based on this.
Similar links:
English is not my mother tongue; please excuse any errors on my part.