Skip to content

Commit 5b02035

Browse files
committed
fix-none-value
1 parent 738ba43 commit 5b02035

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

IPython/core/guarded_eval.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,17 +660,18 @@ def _handle_assign(node: ast.Assign, context: EvaluationContext):
660660

661661
def _handle_annassign(node, context):
662662
annotation_value = _resolve_annotation(eval_node(node.annotation, context), context)
663-
value = node.value
664663

665664
# Use Value for generic types
666-
use_value = isinstance(annotation_value, GENERIC_CONTAINER_TYPES)
665+
use_value = (
666+
isinstance(annotation_value, GENERIC_CONTAINER_TYPES) and node.value is not None
667+
)
667668

668669
# LOCAL VARIABLE
669670
if getattr(node, "simple", False) and isinstance(node.target, ast.Name):
670671
name = node.target.id
671672
if use_value:
672673
return _handle_assign(
673-
ast.Assign(targets=[node.target], value=value), context
674+
ast.Assign(targets=[node.target], value=node.value), context
674675
)
675676
context.transient_locals[name] = annotation_value
676677
return None
@@ -680,7 +681,7 @@ def _handle_annassign(node, context):
680681
attr = node.target.attr
681682
if use_value:
682683
return _handle_assign(
683-
ast.Assign(targets=[node.target], value=value), context
684+
ast.Assign(targets=[node.target], value=node.value), context
684685
)
685686
context.class_transients[attr] = annotation_value
686687
return None

0 commit comments

Comments
 (0)