summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2015-11-30 10:37:47 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2015-11-30 10:37:47 +0200
commit35ae9f42e61dfd091107c5a9af21c70dbb2ef806 (patch)
tree82e3fc154fb0cb53ac5d52bceca60e4fa1b05a18
parent9a2f701f1cbed4ae892383f45d0d1416d337b6d9 (diff)
downloadpylint-35ae9f42e61dfd091107c5a9af21c70dbb2ef806.tar.gz
Don't emit unsubscriptable-object if the node is found inside an abstract class. Closes #685.
-rw-r--r--pylint/checkers/typecheck.py6
-rw-r--r--pylint/test/functional/unsubscriptable_value.py25
2 files changed, 31 insertions, 0 deletions
diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py
index fa67311..86b01b4 100644
--- a/pylint/checkers/typecheck.py
+++ b/pylint/checkers/typecheck.py
@@ -834,9 +834,15 @@ accessed. Python regular expressions are accepted.'}
self.add_message('unsubscriptable-object',
args=node.value.as_string(),
node=node.value)
+ return
+
infered = safe_infer(node.value)
if infered is None or infered is astroid.YES:
return
+
+ if is_inside_abstract_class(node):
+ return
+
if not supports_subscript(infered):
self.add_message('unsubscriptable-object',
args=node.value.as_string(),
diff --git a/pylint/test/functional/unsubscriptable_value.py b/pylint/test/functional/unsubscriptable_value.py
index 7f2ceae..4f1848a 100644
--- a/pylint/test/functional/unsubscriptable_value.py
+++ b/pylint/test/functional/unsubscriptable_value.py
@@ -88,3 +88,28 @@ from collections import deque
deq = deque(maxlen=10)
deq.append(42)
deq[0]
+
+
+class AbstractClass(object):
+
+ def __init__(self):
+ self.ala = {i for i in range(10)}
+ self.bala = [i for i in range(10)]
+ self.portocala = None
+
+ def test_unsubscriptable(self):
+ self.bala[0]
+ self.portocala[0]
+
+
+class ClassMixin(object):
+
+ def __init__(self):
+ self.ala = {i for i in range(10)}
+ self.bala = [i for i in range(10)]
+ self.portocala = None
+
+ def test_unsubscriptable(self):
+ self.bala[0]
+ self.portocala[0]
+ \ No newline at end of file