@@ -901,12 +901,40 @@ def dummy_function(*args, **kwargs):
901901 return _handle_assign (node , context )
902902 if isinstance (node , ast .AnnAssign ):
903903 if node .simple :
904- value = _resolve_annotation (eval_node (node .annotation , context ), context )
905- context .transient_locals [node .target .id ] = value
904+ annotation_value = _resolve_annotation (
905+ eval_node (node .annotation , context ), context
906+ )
907+ # If there's an actual value and annotation is generic, use value itself
908+ if node .value is not None and type (annotation_value ) in (
909+ dict ,
910+ list ,
911+ set ,
912+ tuple ,
913+ frozenset ,
914+ ):
915+ assign_node = ast .Assign (targets = [node .target ], value = node .value )
916+ _handle_assign (assign_node , context )
917+ else :
918+ context .transient_locals [node .target .id ] = annotation_value
919+
906920 # Handle non-simple annotated assignments only for self.x: type = value
907921 if _is_instance_attribute_assignment (node .target , context ):
908- value = _resolve_annotation (eval_node (node .annotation , context ), context )
909- context .class_transients [node .target .attr ] = value
922+ annotation_value = _resolve_annotation (
923+ eval_node (node .annotation , context ), context
924+ )
925+
926+ if node .value is not None and annotation_value in (
927+ dict ,
928+ list ,
929+ set ,
930+ tuple ,
931+ frozenset ,
932+ ):
933+ assign_node = ast .Assign (targets = [node .target ], value = node .value )
934+ _handle_assign (assign_node , context )
935+ else :
936+ context .class_transients [node .target .attr ] = annotation_value
937+
910938 return None
911939 if isinstance (node , ast .Expression ):
912940 return eval_node (node .body , context )
0 commit comments