From 558da6531006902e446b30d4f2b7dbddad768ef3 Mon Sep 17 00:00:00 2001 From: cpopa Date: Thu, 9 Jan 2014 15:38:28 +0200 Subject: Ignore non-inferable nodes, add test case for non-inferable nodes. --- checkers/base.py | 2 ++ test/input/func_bad_reversed_sequence.py | 7 +++++++ test/messages/func_bad_reversed_sequence.txt | 14 +++++++------- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/checkers/base.py b/checkers/base.py index 5df0477..cf4304c 100644 --- a/checkers/base.py +++ b/checkers/base.py @@ -711,6 +711,8 @@ functions, methods except NoSuchArgumentError: self.add_message('missing-reversed-argument', node=node) else: + if argument is astroid.YES: + return if argument is None: # nothing was infered # try to see if we have iter() diff --git a/test/input/func_bad_reversed_sequence.py b/test/input/func_bad_reversed_sequence.py index 31c59c0..a394e53 100644 --- a/test/input/func_bad_reversed_sequence.py +++ b/test/input/func_bad_reversed_sequence.py @@ -31,6 +31,12 @@ class SecondBadReversed(object): class ThirdBadReversed(dict): """ dict subclass """ +def uninferable(seq): + """ This can't be infered at this moment, + make sure we don't have a false positive. + """ + return reversed(seq) + def test(): """ test function """ seq = reversed() @@ -49,4 +55,5 @@ def test(): seq = reversed(lambda: None) seq = reversed(deque([])) seq = reversed("123") + seq = uninferable([1, 2, 3]) return seq diff --git a/test/messages/func_bad_reversed_sequence.txt b/test/messages/func_bad_reversed_sequence.txt index 712cff2..6e85197 100644 --- a/test/messages/func_bad_reversed_sequence.txt +++ b/test/messages/func_bad_reversed_sequence.txt @@ -1,9 +1,9 @@ -E: 36:test: Missing argument to reversed() -E: 37:test: The first reversed() argument is not a sequence -E: 40:test: The first reversed() argument is not a sequence -E: 41:test: The first reversed() argument is not a sequence -E: 42:test: The first reversed() argument is not a sequence -E: 45:test: The first reversed() argument is not a sequence +E: 42:test: Missing argument to reversed() +E: 43:test: The first reversed() argument is not a sequence E: 46:test: The first reversed() argument is not a sequence +E: 47:test: The first reversed() argument is not a sequence E: 48:test: The first reversed() argument is not a sequence -E: 49:test: The first reversed() argument is not a sequence \ No newline at end of file +E: 51:test: The first reversed() argument is not a sequence +E: 52:test: The first reversed() argument is not a sequence +E: 54:test: The first reversed() argument is not a sequence +E: 55:test: The first reversed() argument is not a sequence \ No newline at end of file -- cgit v1.2.1