Ignore non-inferable nodes, add test case for non-inferable nodes.

authorcpopa
changeset23ac3433e7dd
branchreversed
phasepublic
hiddenno
parent revision#9d6c5002720f Remove incomplete-protocol warning.
child revision#ad535eb4cbad Close branch reversed, #57cb6bfd288b Merged in PCManticore/pylint/reversed (pull request #84)
files modified by this revision
checkers/base.py
test/input/func_bad_reversed_sequence.py
test/messages/func_bad_reversed_sequence.txt
# HG changeset patch
# User cpopa
# Date 1389274708 -7200
# Thu Jan 09 15:38:28 2014 +0200
# Branch reversed
# Node ID 23ac3433e7dd1554caa40d95a35b50d9c2a02bc7
# Parent 9d6c5002720f470137adec1cb3adba1e8e6f2a97
Ignore non-inferable nodes, add test case for non-inferable nodes.

diff --git a/checkers/base.py b/checkers/base.py
@@ -709,10 +709,12 @@
1          try:
2              argument = safe_infer(get_argument_from_call(node, position=0))
3          except NoSuchArgumentError:
4              self.add_message('missing-reversed-argument', node=node)
5          else:
6 +            if argument is astroid.YES:
7 +                return
8              if argument is None:
9                  # nothing was infered
10                  # try to see if we have iter()
11                  if (isinstance(node.args[0], astroid.CallFunc) and
12                      node.args[0].func.name == 'iter'):
diff --git a/test/input/func_bad_reversed_sequence.py b/test/input/func_bad_reversed_sequence.py
@@ -29,10 +29,16 @@
13          return index
14 
15  class ThirdBadReversed(dict):
16      """ dict subclass """
17 
18 +def uninferable(seq):
19 +    """ This can't be infered at this moment,
20 +    make sure we don't have a false positive.
21 +    """
22 +    return reversed(seq)
23 +
24  def test():
25      """ test function """
26      seq = reversed()
27      seq = reversed(None)
28      seq = reversed([1, 2, 3])
@@ -47,6 +53,7 @@
29      seq = reversed(range(100))
30      seq = reversed(ThirdBadReversed())
31      seq = reversed(lambda: None)
32      seq = reversed(deque([]))
33      seq = reversed("123")
34 +    seq = uninferable([1, 2, 3])
35      return seq
diff --git a/test/messages/func_bad_reversed_sequence.txt b/test/messages/func_bad_reversed_sequence.txt
@@ -1,9 +1,9 @@
36 -E: 36:test: Missing argument to reversed()

37 -E: 37:test: The first reversed() argument is not a sequence

38 -E: 40:test: The first reversed() argument is not a sequence

39 -E: 41:test: The first reversed() argument is not a sequence

40 -E: 42:test: The first reversed() argument is not a sequence

41 -E: 45:test: The first reversed() argument is not a sequence

42 +E: 42:test: Missing argument to reversed()

43 +E: 43:test: The first reversed() argument is not a sequence

44  E: 46:test: The first reversed() argument is not a sequence

45 +E: 47:test: The first reversed() argument is not a sequence

46  E: 48:test: The first reversed() argument is not a sequence

47 -E: 49:test: The first reversed() argument is not a sequence
48 \ No newline at end of file
49 +E: 51:test: The first reversed() argument is not a sequence

50 +E: 52:test: The first reversed() argument is not a sequence

51 +E: 54:test: The first reversed() argument is not a sequence

52 +E: 55:test: The first reversed() argument is not a sequence
53 \ No newline at end of file