gh-138151: Fix annotationlib handling of multiple nonlocals (#138164)

This commit is contained in:
Jelle Zijlstra 2025-11-03 07:22:32 -08:00 committed by GitHub
parent d590685297
commit b1027d4762
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 45 additions and 13 deletions

View file

@ -1194,6 +1194,21 @@ class RaisesAttributeError:
},
)
def test_nonlocal_in_annotation_scope(self):
class Demo:
nonlocal sequence_b
x: sequence_b
y: sequence_b[int]
fwdrefs = get_annotations(Demo, format=Format.FORWARDREF)
self.assertIsInstance(fwdrefs["x"], ForwardRef)
self.assertIsInstance(fwdrefs["y"], ForwardRef)
sequence_b = list
self.assertIs(fwdrefs["x"].evaluate(), list)
self.assertEqual(fwdrefs["y"].evaluate(), list[int])
def test_raises_error_from_value(self):
# test that if VALUE is the only supported format, but raises an error
# that error is propagated from get_annotations