File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -9788,6 +9788,19 @@ class B(str): ...
97889788 self .assertIs (type (field_c2 .__metadata__ [0 ]), float )
97899789 self .assertIs (type (field_c3 .__metadata__ [0 ]), bool )
97909790
9791+ def test_forwardref_partial_evaluation (self ):
9792+ # Test that Annotated partially evaluates if it contains a ForwardRef
9793+ # See: https://github.com/python/cpython/issues/137706
9794+ def f (x : Annotated [undefined , '' ]): pass
9795+
9796+ ann = annotationlib .get_annotations (f , format = annotationlib .Format .FORWARDREF )
9797+
9798+ # Test that the attributes are retrievable from the partially evaluated annotation
9799+ x_ann = ann ['x' ]
9800+ self .assertIs (get_origin (x_ann ), Annotated )
9801+ self .assertEqual (x_ann .__origin__ , EqualToForwardRef ('undefined' , owner = f ))
9802+ self .assertEqual (x_ann .__metadata__ , ('' ,))
9803+
97919804
97929805class TypeAliasTests (BaseTestCase ):
97939806 def test_canonical_usage_with_variable_annotation (self ):
Original file line number Diff line number Diff line change @@ -1033,8 +1033,10 @@ def evaluate_forward_ref(
10331033
10341034
10351035def _is_unpacked_typevartuple (x : Any ) -> bool :
1036+ # Need to check 'is True' here
1037+ # See: https://github.com/python/cpython/issues/137706
10361038 return ((not isinstance (x , type )) and
1037- getattr (x , '__typing_is_unpacked_typevartuple__' , False ))
1039+ getattr (x , '__typing_is_unpacked_typevartuple__' , False ) is True )
10381040
10391041
10401042def _is_typevar_like (x : Any ) -> bool :
You can’t perform that action at this time.
0 commit comments