@@ -3464,8 +3464,9 @@ def record_special_form_lvalue(self, s: AssignmentStmt) -> None:
3464
3464
def analyze_enum_assign (self , s : AssignmentStmt ) -> bool :
3465
3465
"""Check if s defines an Enum."""
3466
3466
if isinstance (s .rvalue , CallExpr ) and isinstance (s .rvalue .analyzed , EnumCallExpr ):
3467
- # Already analyzed enum -- nothing to do here.
3468
- return True
3467
+ # This is an analyzed enum definition.
3468
+ # It is valid iff it can be stored correctly, failures were already reported.
3469
+ return self ._is_single_name_assignment (s )
3469
3470
return self .enum_call_analyzer .process_enum_call (s , self .is_func_scope ())
3470
3471
3471
3472
def analyze_namedtuple_assign (self , s : AssignmentStmt ) -> bool :
@@ -3474,7 +3475,9 @@ def analyze_namedtuple_assign(self, s: AssignmentStmt) -> bool:
3474
3475
if s .rvalue .analyzed .info .tuple_type and not has_placeholder (
3475
3476
s .rvalue .analyzed .info .tuple_type
3476
3477
):
3477
- return True # This is a valid and analyzed named tuple definition, nothing to do here.
3478
+ # This is an analyzed named tuple definition.
3479
+ # It is valid iff it can be stored correctly, failures were already reported.
3480
+ return self ._is_single_name_assignment (s )
3478
3481
if len (s .lvalues ) != 1 or not isinstance (s .lvalues [0 ], (NameExpr , MemberExpr )):
3479
3482
return False
3480
3483
lvalue = s .lvalues [0 ]
@@ -3515,8 +3518,9 @@ def analyze_typeddict_assign(self, s: AssignmentStmt) -> bool:
3515
3518
if s .rvalue .analyzed .info .typeddict_type and not has_placeholder (
3516
3519
s .rvalue .analyzed .info .typeddict_type
3517
3520
):
3518
- # This is a valid and analyzed typed dict definition, nothing to do here.
3519
- return True
3521
+ # This is an analyzed typed dict definition.
3522
+ # It is valid iff it can be stored correctly, failures were already reported.
3523
+ return self ._is_single_name_assignment (s )
3520
3524
if len (s .lvalues ) != 1 or not isinstance (s .lvalues [0 ], (NameExpr , MemberExpr )):
3521
3525
return False
3522
3526
lvalue = s .lvalues [0 ]
@@ -3540,6 +3544,9 @@ def analyze_typeddict_assign(self, s: AssignmentStmt) -> bool:
3540
3544
self .setup_alias_type_vars (defn )
3541
3545
return True
3542
3546
3547
+ def _is_single_name_assignment (self , s : AssignmentStmt ) -> bool :
3548
+ return len (s .lvalues ) == 1 and isinstance (s .lvalues [0 ], NameExpr )
3549
+
3543
3550
def analyze_lvalues (self , s : AssignmentStmt ) -> None :
3544
3551
# We cannot use s.type, because analyze_simple_literal_type() will set it.
3545
3552
explicit = s .unanalyzed_type is not None
0 commit comments