File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 1
1
# Python test set -- part 2, opcodes
2
2
3
3
import unittest
4
- from test import ann_module
4
+ from test import ann_module , support
5
5
6
6
class OpcodeTest (unittest .TestCase ):
7
7
@@ -42,10 +42,14 @@ def test_use_existing_annotations(self):
42
42
self .assertEqual (ns ['__annotations__' ], {'x' : int , 1 : 2 })
43
43
44
44
def test_do_not_recreate_annotations (self ):
45
- class C :
46
- del __annotations__
47
- with self .assertRaises (NameError ):
48
- x : int
45
+ annotations = {}
46
+ # Don't rely on the existence of the '__annotations__' global.
47
+ with support .swap_item (globals (), '__annotations__' , annotations ):
48
+ class C :
49
+ del __annotations__
50
+ x : int # Updates the '__annotations__' global.
51
+ self .assertIn ('x' , annotations )
52
+ self .assertIs (annotations ['x' ], int )
49
53
50
54
def test_raise_class_exceptions (self ):
51
55
You can’t perform that action at this time.
0 commit comments