From deac58ed822c6cd819e916e6c3d1736c7adfa31e Mon Sep 17 00:00:00 2001 From: 93578237 <43147888+93578237@users.noreply.github.com> Date: Mon, 9 Feb 2026 16:06:50 -0500 Subject: [6.0.x] Fixed #36903 -- Fixed further NameErrors when inspecting functions with deferred annotations. Provide a wrapper for safe introspection of user functions on Python 3.14+. Follow-up to 601914722956cc41f1f2c53972d669ddee6ffc04. Backport of 56ed37e17e5b1a509aa68a0c797dcff34fcc1366 from main. --- tests/template_tests/tests.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/template_tests/tests.py') diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py index 7364c7ca64..573fd9db2e 100644 --- a/tests/template_tests/tests.py +++ b/tests/template_tests/tests.py @@ -1,10 +1,16 @@ import sys +import unittest +from typing import TYPE_CHECKING from django.template import Context, Engine, TemplateDoesNotExist, TemplateSyntaxError from django.template.base import UNKNOWN_SOURCE from django.test import SimpleTestCase, override_settings from django.urls import NoReverseMatch from django.utils import translation +from django.utils.version import PY314 + +if TYPE_CHECKING: + type AnnotatedKwarg = str class TemplateTestMixin: @@ -221,6 +227,21 @@ class TemplateTestMixin: template = self._engine().from_string("{{ description.count }}") self.assertEqual(template.render(Context({"description": "test"})), "") + @unittest.skipUnless(PY314, "Deferred annotations are Python 3.14+ only") + def test_callable_uses_deferred_annotations(self): + """ + Missing required arguments are gracefully handled when a signature uses + deferred annotations. + """ + + class MyObject: + @staticmethod + def uses_deferred_annotations(value: AnnotatedKwarg): + return value + + template = self._engine().from_string("{{ obj.uses_deferred_annotations }}") + self.assertEqual(template.render(Context({"obj": MyObject()})), "") + class TemplateTests(TemplateTestMixin, SimpleTestCase): debug_engine = False -- cgit v1.3