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:51:26 -0500 |
| commit | da1dfe64c821ba03ca7b0c936184cca1ad641316 (patch) | |
| tree | d0a0fdfed6174f8d2fa3cc47e4d439edd2599416 /tests/template_tests/test_parser.py | |
| parent | e2ddec431395330b423ef193548f374b5c2f395e (diff) | |
[5.2.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 'tests/template_tests/test_parser.py')
| -rw-r--r-- | tests/template_tests/test_parser.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/template_tests/test_parser.py b/tests/template_tests/test_parser.py index eb3bb49113..199148970f 100644 --- a/tests/template_tests/test_parser.py +++ b/tests/template_tests/test_parser.py @@ -3,6 +3,8 @@ Testing some internals of the template processing. These are *not* examples to be copied in user code. """ +import unittest + from django.template import Library, TemplateSyntaxError from django.template.base import ( FilterExpression, @@ -14,6 +16,7 @@ from django.template.base import ( ) from django.template.defaultfilters import register as filter_library from django.test import SimpleTestCase +from django.utils.version import PY314 class ParserTests(SimpleTestCase): @@ -148,3 +151,17 @@ class ParserTests(SimpleTestCase): '1|two_one_opt_arg:"1"', ): FilterExpression(expr, parser) + + @unittest.skipUnless(PY314, "Deferred annotations are Python 3.14+ only") + def test_filter_deferred_annotation(self): + register = Library() + + @register.filter("example") + def example_filter(value: str, arg: SomeType): # NOQA: F821 + return f"{value}_{arg}" + + result = FilterExpression.args_check( + "example", example_filter, ["extra_example"] + ) + + self.assertIs(result, True) |
