#36712: Deferred Annotations on Template Tags lead to TypeError with Python 3.14
-------------------------------------+-------------------------------------
Reporter: Patrick Rauscher | Type:
| Uncategorized
Status: new | Component:
| Uncategorized
Version: 5.2 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Similar to #36696 (which covered mainly Signals) this covers templatetags,
where issues may happen when using SafeText:
{{{
from typing import TYPE_CHECKING
from django import template
from django.utils.html import escape
if TYPE_CHECKING:
from django.utils.safestring import SafeText
register = template.Library()
@register.filter("example")
def example_filter(value: str) -> SafeText:
return escape(value)
}}}
When using the templatetag, `django/template/base.py` line 763 (in django
5.2.8) will call `inspect.getfullargspec` for the filter, leading to a
NameError which gets translated by inspect to a `TypeError: unsupported
callable`. After searching a bit through the code this may also happen
with views, as several parts of django use inspect directly for different
checks (e.g. for templatetags it is used to check the number of
arguments).
Not sure if this is a bug in python or django yet. One solution in django
would be to replace direct calls to `inspect.signature` or
`inspect.getfullargspec` (which uses `inspect.signature` internally
according to python docs, but does not allow to specify an
`annotation_format`.
--
Ticket URL: <
https://code.djangoproject.com/ticket/36712>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.