@@ -567,7 +567,7 @@ def _validate_policy_overrides(
567567 return all_good
568568
569569
570- def is_type_annotation (obj ) -> bool :
570+ def _is_type_annotation (obj ) -> bool :
571571 """
572572 Returns True if obj is a type annotation, False otherwise.
573573 """
@@ -793,7 +793,7 @@ def eval_node(node: Union[ast.AST, None], context: EvaluationContext):
793793
794794 if is_property :
795795 if return_type is not None :
796- if is_type_annotation (return_type ):
796+ if _is_type_annotation (return_type ):
797797 context .transient_locals [node .name ] = _resolve_annotation (
798798 return_type , context
799799 )
@@ -809,7 +809,7 @@ def dummy_function(*args, **kwargs):
809809 pass
810810
811811 if return_type is not None :
812- if is_type_annotation (return_type ):
812+ if _is_type_annotation (return_type ):
813813 dummy_function .__annotations__ ["return" ] = return_type
814814 else :
815815 dummy_function .__inferred_return__ = return_type
@@ -933,18 +933,18 @@ def dummy_function(*args, **kwargs):
933933 if isinstance (node , ast .Assign ):
934934 return _handle_assign (node , context )
935935 if isinstance (node , ast .AnnAssign ):
936- context .current_value = getattr (node , "value" , None )
936+ context_with_value = context .replace ( current_value = getattr (node , "value" , None ) )
937937 if node .simple :
938- annotation_result = eval_node (node .annotation , context )
939- if is_type_annotation (annotation_result ):
938+ annotation_result = eval_node (node .annotation , context_with_value )
939+ if _is_type_annotation (annotation_result ):
940940 value = _resolve_annotation (annotation_result , context )
941941 else :
942942 value = annotation_result
943943 context .transient_locals [node .target .id ] = value
944944 # Handle non-simple annotated assignments only for self.x: type = value
945945 if _is_instance_attribute_assignment (node .target , context ):
946- annotation_result = eval_node (node .annotation , context )
947- if is_type_annotation (annotation_result ):
946+ annotation_result = eval_node (node .annotation , context_with_value )
947+ if _is_type_annotation (annotation_result ):
948948 value = _resolve_annotation (annotation_result , context )
949949 else :
950950 value = annotation_result
@@ -966,7 +966,11 @@ def dummy_function(*args, **kwargs):
966966 if isinstance (node , ast .BinOp ):
967967 left = eval_node (node .left , context )
968968 right = eval_node (node .right , context )
969- if is_type_annotation (left ) and is_type_annotation (right ):
969+ if (
970+ isinstance (node .op , ast .BitOr )
971+ and _is_type_annotation (left )
972+ and _is_type_annotation (right )
973+ ):
970974 left_duck = (
971975 _Duck (dict .fromkeys (dir (left )))
972976 if policy .can_call (left .__dir__ )
0 commit comments