MCPcopy Index your code
hub / github.com/ipython/ipython / _handle_annassign

Function _handle_annassign

IPython/core/guarded_eval.py:692–725  ·  view source on GitHub ↗
(node, context)

Source from the content-addressed store, hash-verified

690
691
692def _handle_annassign(node, context):
693 context_with_value = context.replace(current_value=getattr(node, "value", None))
694 annotation_result = eval_node(node.annotation, context_with_value)
695 if _is_type_annotation(annotation_result):
696 annotation_value = _resolve_annotation(annotation_result, context)
697 # Use Value for generic types
698 use_value = (
699 isinstance(annotation_value, GENERIC_CONTAINER_TYPES) and node.value is not None
700 )
701 else:
702 annotation_value = annotation_result
703 use_value = False
704
705 # LOCAL VARIABLE
706 if getattr(node, "simple", False) and isinstance(node.target, ast.Name):
707 name = node.target.id
708 if use_value:
709 return _handle_assign(
710 ast.Assign(targets=[node.target], value=node.value), context
711 )
712 context.transient_locals[name] = annotation_value
713 return None
714
715 # INSTANCE ATTRIBUTE
716 if _is_instance_attribute_assignment(node.target, context):
717 attr = node.target.attr
718 if use_value:
719 return _handle_assign(
720 ast.Assign(targets=[node.target], value=node.value), context
721 )
722 context.class_transients[attr] = annotation_value
723 return None
724
725 return None
726
727def _extract_args_and_kwargs(node: ast.Call, context: EvaluationContext):
728 args = [eval_node(arg, context) for arg in node.args]

Callers 1

eval_nodeFunction · 0.85

Calls 6

_is_type_annotationFunction · 0.85
_resolve_annotationFunction · 0.85
_handle_assignFunction · 0.85
replaceMethod · 0.80
eval_nodeFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…