Skip to content

Commit 5dab490

Browse files
authored
gh-141174: Test re-stringifying a ForwardRef (#155689)
Test that re-evaluating a `ForwardRef` with `STRING` format uses the cache
1 parent 9f87800 commit 5dab490

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)