Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Test dict cell closure with multiple variables
  • Loading branch information
dr-carlos committed Nov 6, 2025
commit aea588700cec9c5c7c47144c874b7d58eba96840
24 changes: 24 additions & 0 deletions Lib/test/test_annotationlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@ def inner(arg: x):
anno = get_annotations(inner, format=Format.FORWARDREF)
self.assertEqual(anno["arg"], x)

def test_multiple_closure(self):
def inner(arg: x[y]):
pass

fwdref = get_annotations(inner, format=Format.FORWARDREF)["arg"]
self.assertIsInstance(fwdref, ForwardRef)
self.assertEqual(fwdref.__forward_arg__, "x[y]")
with self.assertRaises(NameError):
fwdref.evaluate()

y = str
fwdref = get_annotations(inner, format=Format.FORWARDREF)["arg"]
self.assertIsInstance(fwdref, ForwardRef)
extra_name, extra_val = next(iter(fwdref.__extra_names__.items()))
self.assertEqual(fwdref.__forward_arg__.replace(extra_name, extra_val.__name__), "x[str]")
with self.assertRaises(NameError):
fwdref.evaluate()

x = list
self.assertEqual(fwdref.evaluate(), x[y])

fwdref = get_annotations(inner, format=Format.FORWARDREF)["arg"]
self.assertEqual(fwdref, x[y])

def test_function(self):
def f(x: int, y: doesntexist):
pass
Expand Down