From f794565fe7535b2f4a2c112f7955dac3059cddb4 Mon Sep 17 00:00:00 2001 From: dr-carlos Date: Thu, 13 Aug 2026 19:38:36 +0930 Subject: [PATCH] Test that re-evaluating a `ForwardRef` with `STRING` format uses the cache --- Lib/test/test_annotationlib.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lib/test/test_annotationlib.py b/Lib/test/test_annotationlib.py index 5087c3ca425f1fc..5bfcf5ce4131e32 100644 --- a/Lib/test/test_annotationlib.py +++ b/Lib/test/test_annotationlib.py @@ -2133,8 +2133,13 @@ def f(a: unknown | str | int | list[str] | tuple[int, ...]): ... self.assertIsNone(fr.__resolved_str_cache__) self.assertEqual(fr.evaluate(format=Format.STRING), "unknown | str | int | list[str] | tuple[int, ...]") + + # Test that the cache is now set correctly self.assertEqual(fr.__resolved_str_cache__, "unknown | str | int | list[str] | tuple[int, ...]") + # Test that future evaluations return the same cache + self.assertIs(fr.evaluate(format=Format.STRING), fr.__resolved_str_cache__) + def test_evaluate_forwardref_format(self): fr = ForwardRef("undef") evaluated = fr.evaluate(format=Format.FORWARDREF)