@@ -42,11 +42,14 @@ def test_enum(self):
42
42
self .assertEqual (Format .VALUE .value , 1 )
43
43
self .assertEqual (Format .VALUE , 1 )
44
44
45
- self .assertEqual (Format .FORWARDREF .value , 2 )
46
- self .assertEqual (Format .FORWARDREF , 2 )
45
+ self .assertEqual (Format .VALUE_WITH_FAKE_GLOBALS .value , 2 )
46
+ self .assertEqual (Format .VALUE_WITH_FAKE_GLOBALS , 2 )
47
47
48
- self .assertEqual (Format .STRING .value , 3 )
49
- self .assertEqual (Format .STRING , 3 )
48
+ self .assertEqual (Format .FORWARDREF .value , 3 )
49
+ self .assertEqual (Format .FORWARDREF , 3 )
50
+
51
+ self .assertEqual (Format .STRING .value , 4 )
52
+ self .assertEqual (Format .STRING , 4 )
50
53
51
54
52
55
class TestForwardRefFormat (unittest .TestCase ):
@@ -459,19 +462,28 @@ def f2(a: undefined):
459
462
annotationlib .get_annotations (f2 , format = Format .FORWARDREF ),
460
463
{"a" : fwd },
461
464
)
462
- self .assertEqual (annotationlib .get_annotations (f2 , format = 2 ), {"a" : fwd })
465
+ self .assertEqual (annotationlib .get_annotations (f2 , format = 3 ), {"a" : fwd })
463
466
464
467
self .assertEqual (
465
468
annotationlib .get_annotations (f1 , format = Format .STRING ),
466
469
{"a" : "int" },
467
470
)
468
- self .assertEqual (annotationlib .get_annotations (f1 , format = 3 ), {"a" : "int" })
471
+ self .assertEqual (annotationlib .get_annotations (f1 , format = 4 ), {"a" : "int" })
469
472
470
473
with self .assertRaises (ValueError ):
471
- annotationlib .get_annotations (f1 , format = 0 )
474
+ annotationlib .get_annotations (f1 , format = 42 )
472
475
473
- with self .assertRaises (ValueError ):
474
- annotationlib .get_annotations (f1 , format = 4 )
476
+ with self .assertRaisesRegex (
477
+ ValueError ,
478
+ r"The VALUE_WITH_FAKE_GLOBALS format is for internal use only" ,
479
+ ):
480
+ annotationlib .get_annotations (f1 , format = Format .VALUE_WITH_FAKE_GLOBALS )
481
+
482
+ with self .assertRaisesRegex (
483
+ ValueError ,
484
+ r"The VALUE_WITH_FAKE_GLOBALS format is for internal use only" ,
485
+ ):
486
+ annotationlib .get_annotations (f1 , format = 2 )
475
487
476
488
def test_custom_object_with_annotations (self ):
477
489
class C :
@@ -505,6 +517,8 @@ def foo(a: int, b: str):
505
517
506
518
foo .__annotations__ = {"a" : "foo" , "b" : "str" }
507
519
for format in Format :
520
+ if format is Format .VALUE_WITH_FAKE_GLOBALS :
521
+ continue
508
522
with self .subTest (format = format ):
509
523
self .assertEqual (
510
524
annotationlib .get_annotations (foo , format = format ),
@@ -802,6 +816,8 @@ def __annotations__(self):
802
816
803
817
wa = WeirdAnnotations ()
804
818
for format in Format :
819
+ if format is Format .VALUE_WITH_FAKE_GLOBALS :
820
+ continue
805
821
with (
806
822
self .subTest (format = format ),
807
823
self .assertRaisesRegex (
@@ -990,7 +1006,7 @@ def test_pep_695_generics_with_future_annotations_nested_in_function(self):
990
1006
class TestCallEvaluateFunction (unittest .TestCase ):
991
1007
def test_evaluation (self ):
992
1008
def evaluate (format , exc = NotImplementedError ):
993
- if format != 1 :
1009
+ if format > 2 :
994
1010
raise exc
995
1011
return undefined
996
1012
0 commit comments