mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[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:
parent
788104633c
commit
08012a93a8
3 changed files with 45 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue