diff options
| author | Jacob Walls <jacobtylerwalls@gmail.com> | 2025-11-29 18:45:39 -0500 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2025-12-01 20:49:53 -0500 |
| commit | ec7327453d266d31a00060aeb5b9f19e5adfb0a4 (patch) | |
| tree | 991b15a8439d4d768ae6256e378b8e2036c2f51e /django/template | |
| parent | 2e3953f0a2de7bb702d393279d9dbbe2581a21a5 (diff) | |
[6.0.x] Fixed #36712 -- Evaluated type annotations lazily in template tag registration.
Ideally, this will be reverted when an upstream solution is available for
https://github.com/python/cpython/issues/141560.
Thanks Patrick Rauscher for the report and Augusto Pontes for the
first iteration and test.
Backport of 34186e731ca20a2344b1f88fd543a854d6b13a00 from main.
Diffstat (limited to 'django/template')
| -rw-r--r-- | django/template/base.py | 4 | ||||
| -rw-r--r-- | django/template/library.py | 59 |
2 files changed, 34 insertions, 29 deletions
diff --git a/django/template/base.py b/django/template/base.py index 5e541c3960..d6595e38e7 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -60,6 +60,7 @@ from django.template.context import BaseContext from django.utils.deprecation import django_file_prefixes from django.utils.formats import localize from django.utils.html import conditional_escape +from django.utils.inspect import lazy_annotations from django.utils.regex_helper import _lazy_re_compile from django.utils.safestring import SafeData, SafeString, mark_safe from django.utils.text import get_text_list, smart_split, unescape_string_literal @@ -825,7 +826,8 @@ class FilterExpression: # Check to see if a decorator is providing the real function. func = inspect.unwrap(func) - args, _, _, defaults, _, _, _ = inspect.getfullargspec(func) + with lazy_annotations(): + args, _, _, defaults, _, _, _ = inspect.getfullargspec(func) alen = len(args) dlen = len(defaults or []) # Not enough OR Too many diff --git a/django/template/library.py b/django/template/library.py index 3fc4c5ebfc..27af7a6969 100644 --- a/django/template/library.py +++ b/django/template/library.py @@ -4,6 +4,7 @@ from importlib import import_module from inspect import getfullargspec, unwrap from django.utils.html import conditional_escape +from django.utils.inspect import lazy_annotations from .base import Node, Template, token_kwargs from .exceptions import TemplateSyntaxError @@ -110,15 +111,16 @@ class Library: """ def dec(func): - ( - params, - varargs, - varkw, - defaults, - kwonly, - kwonly_defaults, - _, - ) = getfullargspec(unwrap(func)) + with lazy_annotations(): + ( + params, + varargs, + varkw, + defaults, + kwonly, + kwonly_defaults, + _, + ) = getfullargspec(unwrap(func)) function_name = name or func.__name__ @wraps(func) @@ -165,16 +167,16 @@ class Library: def dec(func): nonlocal end_name - - ( - params, - varargs, - varkw, - defaults, - kwonly, - kwonly_defaults, - _, - ) = getfullargspec(unwrap(func)) + with lazy_annotations(): + ( + params, + varargs, + varkw, + defaults, + kwonly, + kwonly_defaults, + _, + ) = getfullargspec(unwrap(func)) function_name = name or func.__name__ if end_name is None: @@ -249,15 +251,16 @@ class Library: """ def dec(func): - ( - params, - varargs, - varkw, - defaults, - kwonly, - kwonly_defaults, - _, - ) = getfullargspec(unwrap(func)) + with lazy_annotations(): + ( + params, + varargs, + varkw, + defaults, + kwonly, + kwonly_defaults, + _, + ) = getfullargspec(unwrap(func)) function_name = name or func.__name__ @wraps(func) |
