@@ -579,8 +579,7 @@ def _handle_assign(node: ast.Assign, context: EvaluationContext):
579579 for i in range (star_or_last_idx ):
580580 transient_locals [targets [i ].id ] = values [i ]
581581 # Check for self.x assignment
582- if class_transients is not None and hasattr (targets [i ], "ctx" ):
583- if _is_instance_attribute_assignment (targets [i ], context ):
582+ if _is_instance_attribute_assignment (targets [i ], context ):
584583 class_transients [targets [i ].attr ] = values [i ]
585584
586585 # Starred if exists
@@ -589,7 +588,7 @@ def _handle_assign(node: ast.Assign, context: EvaluationContext):
589588 transient_locals [targets [star_or_last_idx ].value .id ] = values [
590589 star_or_last_idx :end
591590 ]
592- if class_transients is not None and _is_instance_attribute_assignment (
591+ if _is_instance_attribute_assignment (
593592 targets [star_or_last_idx ], context
594593 ):
595594 class_transients [targets [star_or_last_idx ].attr ] = values [
@@ -601,16 +600,12 @@ def _handle_assign(node: ast.Assign, context: EvaluationContext):
601600 transient_locals [targets [i ].id ] = values [
602601 len (values ) - (len (targets ) - i )
603602 ]
604- if (
605- class_transients is not None
606- and _is_instance_attribute_assignment (targets [i ], context )
607- ):
603+ if _is_instance_attribute_assignment (targets [i ], context ):
608604 class_transients [targets [i ].attr ] = values [
609605 len (values ) - (len (targets ) - i )
610606 ]
611607 else :
612608 if _is_instance_attribute_assignment (target , context ):
613- if class_transients is not None :
614609 class_transients [target .attr ] = value
615610 elif hasattr (target , "id" ):
616611 transient_locals [target .id ] = value
@@ -636,7 +631,8 @@ def _is_instance_attribute_assignment(
636631) -> bool :
637632 """Return True if target is an attribute access on the instance argument."""
638633 return (
639- context .instance_arg_name is not None
634+ context .class_transients is not None
635+ and context .instance_arg_name is not None
640636 and isinstance (target , ast .Attribute )
641637 and isinstance (getattr (target , "value" , None ), ast .Name )
642638 and getattr (target .value , "id" , None ) == context .instance_arg_name
@@ -753,9 +749,7 @@ def dummy_function(*args, **kwargs):
753749 context .transient_locals [node .target .id ] = value
754750 # Handle non-simple annotated assignments only for self.x: type = value
755751 class_transients = getattr (context , "class_transients" , None )
756- if class_transients is not None and _is_instance_attribute_assignment (
757- node .target , context
758- ):
752+ if _is_instance_attribute_assignment (node .target , context ):
759753 value = _resolve_annotation (eval_node (node .annotation , context ), context )
760754 class_transients [node .target .attr ] = value
761755 return None
0 commit comments