33import ast
44from typing import Any
55
6- from ..config import Config
76from ..exceptions import MultipleStatementsError
87from ..problem import Problem
98from .base_visitor import BaseVisitor
@@ -39,36 +38,19 @@ def __init__( # pylint: disable=unused-argument
3938class PLU002Visitor (BaseVisitor ):
4039 """Visitor class for the PLU002 rule."""
4140
42- def __init__ (self , lines : list [ str ], config : Config ) :
41+ def visit_Return (self , node : ast . Return ) -> Any :
4342 """
44- Initialize a PLU002Visitor instance .
43+ Visit a `Return` node .
4544
4645 Args:
47- lines (list[str]): The physical lines.
48- config (Config): Configuration instance for the plugin and visitor.
49- """
50- self ._last_end : int = 0
51- super ().__init__ (lines , config )
52-
53- def visit (self , node : ast .AST ) -> Any :
54- """
55- Visit the specified node.
56-
57- Args:
58- node (ast.AST): The node to visit.
46+ node (ast.Return): The node to visit.
5947
6048 Returns:
61- Any: The value returned by the base class `visit` method .
49+ Any: The result of calling `generic_visit` .
6250 """
63- self ._process_node (node )
64- return super ().visit (node )
65-
66- def _process_node (self , node : ast .AST ):
67- if isinstance (node , ast .Return ):
68- try :
69- actual = self .compute_blanks_before (node )
70- except MultipleStatementsError :
71- return
51+ # pylint: disable=invalid-name
52+ try :
53+ actual = self .compute_blanks_before (node )
7254 if actual != self .config .blanks_before_return :
7355 problem = PLU002Problem (
7456 node .lineno ,
@@ -77,5 +59,6 @@ def _process_node(self, node: ast.AST):
7759 self .config .blanks_before_return ,
7860 )
7961 self .problems .append (problem )
80- elif hasattr (node , "end_lineno" ) and (node .end_lineno is not None ):
81- self ._last_end = node .end_lineno
62+ except MultipleStatementsError :
63+ pass
64+ return self .generic_visit (node )
0 commit comments