@@ -42,11 +42,14 @@ def test_enum(self):
4242 self .assertEqual (Format .VALUE .value , 1 )
4343 self .assertEqual (Format .VALUE , 1 )
4444
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 )
4747
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 )
5053
5154
5255class TestForwardRefFormat (unittest .TestCase ):
@@ -459,19 +462,28 @@ def f2(a: undefined):
459462 annotationlib .get_annotations (f2 , format = Format .FORWARDREF ),
460463 {"a" : fwd },
461464 )
462- self .assertEqual (annotationlib .get_annotations (f2 , format = 2 ), {"a" : fwd })
465+ self .assertEqual (annotationlib .get_annotations (f2 , format = 3 ), {"a" : fwd })
463466
464467 self .assertEqual (
465468 annotationlib .get_annotations (f1 , format = Format .STRING ),
466469 {"a" : "int" },
467470 )
468- self .assertEqual (annotationlib .get_annotations (f1 , format = 3 ), {"a" : "int" })
471+ self .assertEqual (annotationlib .get_annotations (f1 , format = 4 ), {"a" : "int" })
469472
470473 with self .assertRaises (ValueError ):
471- annotationlib .get_annotations (f1 , format = 0 )
474+ annotationlib .get_annotations (f1 , format = 42 )
472475
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 )
475487
476488 def test_custom_object_with_annotations (self ):
477489 class C :
@@ -505,6 +517,8 @@ def foo(a: int, b: str):
505517
506518 foo .__annotations__ = {"a" : "foo" , "b" : "str" }
507519 for format in Format :
520+ if format is Format .VALUE_WITH_FAKE_GLOBALS :
521+ continue
508522 with self .subTest (format = format ):
509523 self .assertEqual (
510524 annotationlib .get_annotations (foo , format = format ),
@@ -802,6 +816,8 @@ def __annotations__(self):
802816
803817 wa = WeirdAnnotations ()
804818 for format in Format :
819+ if format is Format .VALUE_WITH_FAKE_GLOBALS :
820+ continue
805821 with (
806822 self .subTest (format = format ),
807823 self .assertRaisesRegex (
@@ -990,7 +1006,7 @@ def test_pep_695_generics_with_future_annotations_nested_in_function(self):
9901006class TestCallEvaluateFunction (unittest .TestCase ):
9911007 def test_evaluation (self ):
9921008 def evaluate (format , exc = NotImplementedError ):
993- if format != 1 :
1009+ if format > 2 :
9941010 raise exc
9951011 return undefined
9961012
0 commit comments