@@ -2686,17 +2686,7 @@ def process_typevar_declaration(self, s: AssignmentStmt) -> bool:
26862686 self .fail ("Cannot declare the type of a type variable" , s )
26872687 return False
26882688
2689- assert isinstance (s .rvalue , CallExpr )
26902689 name = lvalue .name
2691- names = self .current_symbol_table ()
2692- existing = names .get (name )
2693- if existing and not (isinstance (existing .node , PlaceholderNode ) or
2694- # Also give error for another type variable with the same name.
2695- (isinstance (existing .node , TypeVarExpr ) and
2696- existing .node is s .rvalue .analyzed )):
2697- self .fail ("Cannot redefine '%s' as a type variable" % name , s )
2698- return False
2699-
27002690 if not self .check_typevar_name (call , name , s ):
27012691 return False
27022692
@@ -2713,6 +2703,14 @@ def process_typevar_declaration(self, s: AssignmentStmt) -> bool:
27132703 return False
27142704 variance , upper_bound = res
27152705
2706+ existing = self .current_symbol_table ().get (name )
2707+ if existing and not (isinstance (existing .node , PlaceholderNode ) or
2708+ # Also give error for another type variable with the same name.
2709+ (isinstance (existing .node , TypeVarExpr ) and
2710+ existing .node is call .analyzed )):
2711+ self .fail ("Cannot redefine '%s' as a type variable" % name , s )
2712+ return False
2713+
27162714 if self .options .disallow_any_unimported :
27172715 for idx , constraint in enumerate (values , start = 1 ):
27182716 if has_any_from_unimported_type (constraint ):
0 commit comments