From 34186e731ca20a2344b1f88fd543a854d6b13a00 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 29 Nov 2025 18:45:39 -0500 Subject: 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. --- tests/admin_views/test_templatetags.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/admin_views') diff --git a/tests/admin_views/test_templatetags.py b/tests/admin_views/test_templatetags.py index 185fe156a6..e8129cce1d 100644 --- a/tests/admin_views/test_templatetags.py +++ b/tests/admin_views/test_templatetags.py @@ -1,13 +1,17 @@ import datetime +import unittest from django.contrib.admin import ModelAdmin from django.contrib.admin.templatetags.admin_list import date_hierarchy from django.contrib.admin.templatetags.admin_modify import submit_row +from django.contrib.admin.templatetags.base import InclusionAdminNode from django.contrib.auth import get_permission_codename from django.contrib.auth.admin import UserAdmin from django.contrib.auth.models import User +from django.template.base import Token, TokenType from django.test import RequestFactory, TestCase from django.urls import reverse +from django.utils.version import PY314 from .admin import ArticleAdmin, site from .models import Article, Question @@ -131,6 +135,22 @@ class AdminTemplateTagsTest(AdminViewBasicTestCase): self.assertContains(response, "override-pagination") self.assertContains(response, "override-search_form") + @unittest.skipUnless(PY314, "Deferred annotations are Python 3.14+ only") + def test_inclusion_admin_node_deferred_annotation(self): + def action(arg: SomeType = None): # NOQA: F821 + pass + + # This used to raise TypeError via the underlying call to + # inspect.getfullargspec(), which is not ready for deferred + # evaluation of annotations. + InclusionAdminNode( + parser=object(), + token=Token(token_type=TokenType.TEXT, contents="a"), + func=action, + template_name="test.html", + takes_context=False, + ) + class DateHierarchyTests(TestCase): factory = RequestFactory() -- cgit v1.3