[3.14] gh-138151: Fix annotationlib handling of multiple nonlocals (GH-138164) (#140949)

gh-138151: Fix annotationlib handling of multiple nonlocals (GH-138164)
(cherry picked from commit b1027d4762)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-11-03 16:52:01 +01:00 committed by GitHub
parent 788104633c
commit 08012a93a8
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