summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPatrick Rauscher <Patrick.Rauscher@deutschebahn.com>2025-10-30 10:13:14 +0100
committerJacob Walls <jacobtylerwalls@gmail.com>2025-10-31 08:47:32 -0400
commit6775888470317a6d69121779b489bb2dc7350318 (patch)
tree02681a43e26596969cc85ff181f22ffed826099f /tests
parentd5dfffaae52b9dcb4857d42b1e2902290a5c5e3c (diff)
[5.2.x] Fixed #36696 -- Fixed NameError when inspecting functions with deferred annotations.
In Python 3.14, annotations are deferred by default, so we should not assume that the names in them have been imported unconditionally.
Diffstat (limited to 'tests')
-rw-r--r--tests/utils_tests/test_inspect.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/utils_tests/test_inspect.py b/tests/utils_tests/test_inspect.py
index b8359c2508..697b0c4e5d 100644
--- a/tests/utils_tests/test_inspect.py
+++ b/tests/utils_tests/test_inspect.py
@@ -1,6 +1,11 @@
import unittest
+from typing import TYPE_CHECKING
from django.utils import inspect
+from django.utils.version import PY314
+
+if TYPE_CHECKING:
+ from django.utils.safestring import SafeString
class Person:
@@ -100,3 +105,13 @@ class TestInspectMethods(unittest.TestCase):
self.assertIs(inspect.func_accepts_kwargs(Person().just_args), False)
self.assertIs(inspect.func_accepts_kwargs(Person.all_kinds), True)
self.assertIs(inspect.func_accepts_kwargs(Person().just_args), False)
+
+ @unittest.skipUnless(PY314, "Deferred annotations are Python 3.14+ only")
+ def test_func_accepts_kwargs_deferred_annotations(self):
+
+ def func_with_annotations(self, name: str, complex: SafeString) -> None:
+ pass
+
+ # Inspection fails with deferred annotations with python 3.14+. Earlier
+ # Python versions trigger the NameError on module initialization.
+ self.assertIs(inspect.func_accepts_kwargs(func_with_annotations), False)