Skip to content

Commit abce638

Browse files
committed
Test the string representations and a multiple level nested annotation
1 parent c23696a commit abce638

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎Lib/test/test_annotationlib.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,28 @@ def test_nested_deferred(self):
244244
class NestedForwardRefs:
245245
genericalias: Unknown1[str, list[Unknown2]]
246246
annotated: Unknown1[str, typing.Annotated[Unknown2, '']]
247+
extra_nested: Unknown3[tuple[Unknown4[list[Unknown5]]]]
247248

248249
annos = get_annotations(NestedForwardRefs, format=Format.FORWARDREF)
249250

250251
gen = annos['genericalias']
251252
annotated = annos['annotated']
253+
nested = annos['extra_nested']
254+
255+
self.assertEqual(
256+
gen.evaluate(format=Format.STRING),
257+
"Unknown1[str, list[Unknown2]]"
258+
)
259+
260+
self.assertEqual(
261+
annotated.evaluate(format=Format.STRING),
262+
"Unknown1[str, typing.Annotated[Unknown2, '']]",
263+
)
264+
265+
self.assertEqual(
266+
nested.evaluate(format=Format.STRING),
267+
"Unknown3[tuple[Unknown4[list[Unknown5]]]]",
268+
)
252269

253270
Unknown1 = tuple
254271
# Unknown2 is still undefined, these should raise
@@ -269,6 +286,14 @@ class NestedForwardRefs:
269286
tuple[str, typing.Annotated[str, '']],
270287
)
271288

289+
Unknown3 = list
290+
Unknown4 = set
291+
Unknown5 = int
292+
self.assertEqual(
293+
nested.evaluate(),
294+
list[tuple[set[list[int]]]],
295+
)
296+
272297
def test_nested_special_generic(self):
273298
# Test that ForwardRef works correctly for generic aliases that aren't
274299
# created through subscripting

0 commit comments

Comments
 (0)