@@ -6211,9 +6211,11 @@ def add_symbol_table_node(
62116211 if not is_same_symbol (old , new ):
62126212 if isinstance (new , (FuncDef , Decorator , OverloadedFuncDef , TypeInfo )):
62136213 self .add_redefinition (names , name , symbol )
6214- if not (
6215- is_init_only (old )
6216- or (isinstance (new , (FuncDef , Decorator )) and self .set_original_def (old , new ))
6214+ if isinstance (old , Var ) and is_init_only (old ):
6215+ if old .has_explicit_value :
6216+ self .fail ("InitVar with default value cannot be redefined" , context )
6217+ elif not (
6218+ isinstance (new , (FuncDef , Decorator )) and self .set_original_def (old , new )
62176219 ):
62186220 self .name_already_defined (name , context , existing )
62196221 elif name not in self .missing_names [- 1 ] and "*" not in self .missing_names [- 1 ]:
@@ -7200,9 +7202,8 @@ def halt(self, reason: str = ...) -> NoReturn:
72007202 )
72017203
72027204
7203- def is_init_only (node : SymbolNode | None ) -> bool :
7205+ def is_init_only (node : Var ) -> bool :
72047206 return (
7205- isinstance (node , Var )
7206- and isinstance (type := get_proper_type (node .type ), Instance )
7207+ isinstance (type := get_proper_type (node .type ), Instance )
72077208 and type .type .fullname == "dataclasses.InitVar"
72087209 )
0 commit comments