@@ -600,13 +600,15 @@ def collect_attributes(self) -> list[DataclassAttribute] | None:
600600 if not isinstance (lhs , NameExpr ):
601601 continue
602602
603- sym = cls .info .names .get (lhs .name )
603+ attr_name = lhs .name
604+ sym = cls .info .names .get (attr_name )
604605 if sym is None :
605606 # There was probably a semantic analysis error.
606607 continue
607608
608609 node = sym .node
609- assert not isinstance (node , PlaceholderNode )
610+ if isinstance (node , PlaceholderNode ):
611+ continue
610612
611613 if isinstance (node , TypeAlias ):
612614 self ._api .fail (
@@ -622,32 +624,23 @@ def collect_attributes(self) -> list[DataclassAttribute] | None:
622624 # We will issue an error later.
623625 continue
624626 if not isinstance (node , Var ):
625- if name in redefined_attrs and len (redefined_attrs [name ]) > 1 :
626- continue
627- self ._api .fail (
628- f"Dataclass attribute '{ name } ' cannot be a function. "
629- f"Use a variable with type annotation instead." ,
630- stmt ,
631- )
632- continue
633-
634- if not isinstance (node , Var ):
635- if name in redefined_attrs and len (redefined_attrs [name ]) > 1 :
636- if name in last_def_with_type :
627+ if attr_name in redefined_attrs and len (redefined_attrs [attr_name ]) > 1 :
628+ if attr_name in last_def_with_type :
637629 continue
638- last_def = redefined_attrs .get (name , [stmt ])[- 1 ]
630+
631+ last_def = redefined_attrs .get (attr_name , [stmt ])[- 1 ]
639632 if last_def .type is not None :
640- var = Var (name )
633+ var = Var (attr_name )
641634 var .is_property = False
642635 var .info = cls .info
643636 var .line = last_def .line
644637 var .column = last_def .column
645638 var .type = self ._api .anal_type (last_def .type )
646- cls .info .names [name ] = SymbolTableNode (MDEF , var )
639+ cls .info .names [attr_name ] = SymbolTableNode (MDEF , var )
647640 node = var
648641 else :
649642 self ._api .fail (
650- f"Dataclass attribute '{ name } ' cannot be a function. "
643+ f"Dataclass attribute '{ attr_name } ' cannot be a function. "
651644 f"Use a variable with type annotation instead." ,
652645 stmt ,
653646 )
0 commit comments