fix elif-used rule

The bug was introduced when porting the rule from pylint core to an extension

authorLaura Médioni <laura.medioni@logilab.fr>
changesetaeafc897ae82
branchdefault
phasepublic
hiddenno
parent revision#ca87a66feb99 Fix a crash which occurred when old visit methods are encountered
child revision#2871c4d70844 Add else-if-used rule functional test
files modified by this revision
pylint/extensions/check_elif.py
# HG changeset patch
# User Laura Médioni <laura.medioni@logilab.fr>
# Date 1448872139 -3600
# Mon Nov 30 09:28:59 2015 +0100
# Node ID aeafc897ae82bc33288e000b5b322d123e4e52d8
# Parent ca87a66feb994c639b4bc29c5661ec2fec9624ba
fix elif-used rule

The bug was introduced when porting the rule from pylint core to an extension

diff --git a/pylint/extensions/check_elif.py b/pylint/extensions/check_elif.py
@@ -23,31 +23,17 @@
1 
2      def _init(self):
3          self._elifs = []
4          self._if_counter = 0
5 
6 -    def _is_actual_elif(self, node):
7 -        """Check if the given node is an actual elif
8 -
9 -        This is a problem we're having with the builtin ast module,
10 -        which splits `elif` branches into a separate if statement.
11 -        Unfortunately we need to know the exact type in certain
12 -        cases.
13 -        """
14 -
15 -        if isinstance(node.parent, astroid.If):
16 -            orelse = node.parent.orelse
17 -            # current if node must directly follow a "else"
18 -            if orelse and orelse == [node]:
19 -                if self._elifs[self._if_counter]:
20 -                    return True
21 -        return False
22 -
23      def process_tokens(self, tokens):
24          # Process tokens and look for 'if' or 'elif'
25          for _, token, _, _, _ in tokens:
26 -            self._elifs.append(True if token == 'elif' else False)
27 +            if token == 'elif':
28 +                self._elifs.append(True)
29 +            elif token == 'if':
30 +                self._elifs.append(False)
31 
32      def leave_module(self, _):
33          self._init()
34 
35      def visit_ifexp(self, _):