diff options
| author | 93578237 <43147888+93578237@users.noreply.github.com> | 2026-02-09 16:06:50 -0500 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-02-10 17:08:13 -0500 |
| commit | a4999ef1b9790a4c0e793cf0e5c464e9935c3c3a (patch) | |
| tree | f40aea6d8d811cb1ea3e8babc428debd2d175675 /tests/template_tests/tests.py | |
| parent | e9b85373580338c4878d3f930b52c361398065ad (diff) | |
[5.2.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.
Diffstat (limited to 'tests/template_tests/tests.py')
| -rw-r--r-- | tests/template_tests/tests.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py index 7364c7ca64..da03c2d1b5 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, TypeAlias 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: + AnnotatedKwarg: TypeAlias = 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 |
