diff options
author | cpopa <devnull@localhost> | 2013-10-10 15:26:30 +0300 |
---|---|---|
committer | cpopa <devnull@localhost> | 2013-10-10 15:26:30 +0300 |
commit | 80f6ff3444aacd78914d7b311d81c7236fa41d5f (patch) | |
tree | 016bd027788ebf003a85598c2d22949025eb609c | |
parent | 34f02fb9bfe466a80e941faa088b8a5d2d35585a (diff) | |
download | pylint-80f6ff3444aacd78914d7b311d81c7236fa41d5f.tar.gz |
Ignore deques (can't retrieve special methods).
-rw-r--r-- | checkers/base.py | 7 | ||||
-rw-r--r-- | test/input/func_bad_reversed_sequence.py | 3 | ||||
-rw-r--r-- | test/messages/func_bad_reversed_sequence.txt | 14 |
3 files changed, 16 insertions, 8 deletions
diff --git a/checkers/base.py b/checkers/base.py index afe6fd2..db5f2cc 100644 --- a/checkers/base.py +++ b/checkers/base.py @@ -724,7 +724,12 @@ functions, methods break else: break - else: + else: + # check if it is a .deque. It doesn't seem that + # we can retrieve special methods + # from C implemented constructs + if argument._proxied.qname().endswith(".deque"): + return self.add_message('bad-reversed-sequence', node=node) elif not isinstance(argument, (astroid.List, astroid.Tuple)): # everything else is not a proper sequence for reversed() diff --git a/test/input/func_bad_reversed_sequence.py b/test/input/func_bad_reversed_sequence.py index 3bab9b9..71e9067 100644 --- a/test/input/func_bad_reversed_sequence.py +++ b/test/input/func_bad_reversed_sequence.py @@ -1,6 +1,8 @@ """ Checks that reversed() receive proper argument """ # pylint: disable-msg=too-few-public-methods,no-self-use,incomplete-protocol +from collections import deque + __revision__ = 0 class GoodReversed(object): @@ -45,4 +47,5 @@ def test(): seq = reversed(range(100)) seq = reversed(ThirdBadReversed()) seq = reversed(lambda: None) + seq = reversed(deque([])) return seq diff --git a/test/messages/func_bad_reversed_sequence.txt b/test/messages/func_bad_reversed_sequence.txt index 87771ac..62792f1 100644 --- a/test/messages/func_bad_reversed_sequence.txt +++ b/test/messages/func_bad_reversed_sequence.txt @@ -1,8 +1,8 @@ -E: 34:test: Missing argument to reversed()
-E: 35:test: The first reversed() argument is not a sequence
-E: 38:test: The first reversed() argument is not a sequence
-E: 39:test: The first reversed() argument is not a sequence
-E: 43:test: The first reversed() argument is not a sequence
-E: 44:test: The first reversed() argument is not a sequence
+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: 45: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
\ No newline at end of file +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 |