@@ -1009,28 +1009,22 @@ def do_func_def(
10091009 func_def .is_coroutine = True
10101010 if func_type is not None :
10111011 func_type .definition = func_def
1012- func_type .line = lineno
1012+ func_type .set_line ( lineno )
10131013
10141014 if n .decorator_list :
1015- # Set deco_line to the old pre-3.8 lineno, in order to keep
1016- # existing "# type: ignore" comments working:
1017- deco_line = n .decorator_list [0 ].lineno
1018-
10191015 var = Var (func_def .name )
10201016 var .is_ready = False
10211017 var .set_line (lineno )
10221018
10231019 func_def .is_decorated = True
1024- func_def .deco_line = deco_line
1025- func_def .set_line (lineno , n .col_offset , end_line , end_column )
1020+ self .set_line (func_def , n )
10261021
10271022 deco = Decorator (func_def , self .translate_expr_list (n .decorator_list ), var )
10281023 first = n .decorator_list [0 ]
10291024 deco .set_line (first .lineno , first .col_offset , end_line , end_column )
10301025 retval : FuncDef | Decorator = deco
10311026 else :
1032- # FuncDef overrides set_line -- can't use self.set_line
1033- func_def .set_line (lineno , n .col_offset , end_line , end_column )
1027+ self .set_line (func_def , n )
10341028 retval = func_def
10351029 if self .options .include_docstrings :
10361030 func_def .docstring = ast3 .get_docstring (n , clean = False )
@@ -1149,10 +1143,7 @@ def visit_ClassDef(self, n: ast3.ClassDef) -> ClassDef:
11491143 type_args = explicit_type_params ,
11501144 )
11511145 cdef .decorators = self .translate_expr_list (n .decorator_list )
1152- # Set lines to match the old mypy 0.700 lines, in order to keep
1153- # existing "# type: ignore" comments working:
1154- cdef .line = n .lineno
1155- cdef .deco_line = n .decorator_list [0 ].lineno if n .decorator_list else None
1146+ self .set_line (cdef , n )
11561147
11571148 if self .options .include_docstrings :
11581149 cdef .docstring = ast3 .get_docstring (n , clean = False )
@@ -1247,8 +1238,7 @@ def visit_AnnAssign(self, n: ast3.AnnAssign) -> AssignmentStmt:
12471238 line = n .lineno
12481239 if n .value is None : # always allow 'x: int'
12491240 rvalue : Expression = TempNode (AnyType (TypeOfAny .special_form ), no_rhs = True )
1250- rvalue .line = line
1251- rvalue .column = n .col_offset
1241+ self .set_line (rvalue , n )
12521242 else :
12531243 rvalue = self .visit (n .value )
12541244 typ = TypeConverter (self .errors , line = line ).visit (n .annotation )
@@ -1675,19 +1665,7 @@ def visit_Attribute(self, n: Attribute) -> MemberExpr | SuperExpr:
16751665 # Subscript(expr value, slice slice, expr_context ctx)
16761666 def visit_Subscript (self , n : ast3 .Subscript ) -> IndexExpr :
16771667 e = IndexExpr (self .visit (n .value ), self .visit (n .slice ))
1678- self .set_line (e , n )
1679- # alias to please mypyc
1680- is_py38_or_earlier = sys .version_info < (3 , 9 )
1681- if isinstance (n .slice , ast3 .Slice ) or (
1682- is_py38_or_earlier and isinstance (n .slice , ast3 .ExtSlice )
1683- ):
1684- # Before Python 3.9, Slice has no line/column in the raw ast. To avoid incompatibility
1685- # visit_Slice doesn't set_line, even in Python 3.9 on.
1686- # ExtSlice also has no line/column info. In Python 3.9 on, line/column is set for
1687- # e.index when visiting n.slice.
1688- e .index .line = e .line
1689- e .index .column = e .column
1690- return e
1668+ return self .set_line (e , n )
16911669
16921670 # Starred(expr value, expr_context ctx)
16931671 def visit_Starred (self , n : Starred ) -> StarExpr :
@@ -1718,7 +1696,8 @@ def visit_Tuple(self, n: ast3.Tuple) -> TupleExpr:
17181696
17191697 # Slice(expr? lower, expr? upper, expr? step)
17201698 def visit_Slice (self , n : ast3 .Slice ) -> SliceExpr :
1721- return SliceExpr (self .visit (n .lower ), self .visit (n .upper ), self .visit (n .step ))
1699+ e = SliceExpr (self .visit (n .lower ), self .visit (n .upper ), self .visit (n .step ))
1700+ return self .set_line (e , n )
17221701
17231702 # ExtSlice(slice* dims)
17241703 def visit_ExtSlice (self , n : ast3 .ExtSlice ) -> TupleExpr :
0 commit comments