Skip to content

Commit 83197a5

Browse files
[3.14] gh-141174: Test re-stringifying a ForwardRef (GH-155689) (#155708)
Test that re-evaluating a `ForwardRef` with `STRING` format uses the cache (cherry picked from commit 5dab490) Co-authored-by: dr-carlos <77367421+dr-carlos@users.noreply.github.com>
1 parent 48f82d7 commit 83197a5

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

Lib/test/test_annotationlib.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,8 +2133,13 @@ def f(a: unknown | str | int | list[str] | tuple[int, ...]): ...
21332133
self.assertIsNone(fr.__resolved_str_cache__)
21342134

21352135
self.assertEqual(fr.evaluate(format=Format.STRING), "unknown | str | int | list[str] | tuple[int, ...]")
2136+
2137+
# Test that the cache is now set correctly
21362138
self.assertEqual(fr.__resolved_str_cache__, "unknown | str | int | list[str] | tuple[int, ...]")
21372139

2140+
# Test that future evaluations return the same cache
2141+
self.assertIs(fr.evaluate(format=Format.STRING), fr.__resolved_str_cache__)
2142+
21382143
def test_evaluate_forwardref_format(self):
21392144
fr = ForwardRef("undef")
21402145
evaluated = fr.evaluate(format=Format.FORWARDREF)

0 commit comments

Comments
 (0)