64
64
)
65
65
66
66
ANN_MODULE_SOURCE = '''\
67
+ import sys
67
68
from typing import List, Optional
68
69
from functools import wraps
69
70
70
- __annotations__[1] = 2
71
+ try:
72
+ __annotations__[1] = 2
73
+ except NameError:
74
+ assert sys.version_info >= (3, 14)
71
75
72
76
class C:
73
77
@@ -77,8 +81,10 @@ class C:
77
81
x: int = 5; y: str = x; f: Tuple[int, int]
78
82
79
83
class M(type):
80
-
81
- __annotations__['123'] = 123
84
+ try:
85
+ __annotations__['123'] = 123
86
+ except NameError:
87
+ assert sys.version_info >= (3, 14)
82
88
o: type = object
83
89
84
90
(pars): bool = True
@@ -1310,7 +1316,10 @@ def tearDownClass(cls):
1310
1316
del sys .modules [modname ]
1311
1317
1312
1318
def test_get_type_hints_modules (self ):
1313
- ann_module_type_hints = {1 : 2 , 'f' : Tuple [int , int ], 'x' : int , 'y' : str }
1319
+ if sys .version_info >= (3 , 14 ):
1320
+ ann_module_type_hints = {'f' : Tuple [int , int ], 'x' : int , 'y' : str }
1321
+ else :
1322
+ ann_module_type_hints = {1 : 2 , 'f' : Tuple [int , int ], 'x' : int , 'y' : str }
1314
1323
self .assertEqual (gth (self .ann_module ), ann_module_type_hints )
1315
1324
self .assertEqual (gth (self .ann_module2 ), {})
1316
1325
self .assertEqual (gth (self .ann_module3 ), {})
@@ -1319,7 +1328,10 @@ def test_get_type_hints_classes(self):
1319
1328
self .assertEqual (gth (self .ann_module .C , self .ann_module .__dict__ ),
1320
1329
{'y' : Optional [self .ann_module .C ]})
1321
1330
self .assertIsInstance (gth (self .ann_module .j_class ), dict )
1322
- self .assertEqual (gth (self .ann_module .M ), {'123' : 123 , 'o' : type })
1331
+ if sys .version_info >= (3 , 14 ):
1332
+ self .assertEqual (gth (self .ann_module .M ), {'o' : type })
1333
+ else :
1334
+ self .assertEqual (gth (self .ann_module .M ), {'123' : 123 , 'o' : type })
1323
1335
self .assertEqual (gth (self .ann_module .D ),
1324
1336
{'j' : str , 'k' : str , 'y' : Optional [self .ann_module .C ]})
1325
1337
self .assertEqual (gth (self .ann_module .Y ), {'z' : int })
@@ -2992,7 +3004,7 @@ def meth(self): pass # noqa: B027
2992
3004
2993
3005
acceptable_extra_attrs = {
2994
3006
'_is_protocol' , '_is_runtime_protocol' , '__parameters__' ,
2995
- '__init__' , '__annotations__' , '__subclasshook__' ,
3007
+ '__init__' , '__annotations__' , '__subclasshook__' , '__annotate__'
2996
3008
}
2997
3009
self .assertLessEqual (vars (NonP ).keys (), vars (C ).keys () | acceptable_extra_attrs )
2998
3010
self .assertLessEqual (
0 commit comments