From f0e5799175980963b1dc8c2e3e068f022917c4bf Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Mon, 30 Nov 2015 10:37:47 +0200 Subject: Don't emit unsubscriptable-object if the node is found inside an abstract class. Closes #685. --- pylint/checkers/typecheck.py | 3 +++ pylint/test/functional/unsubscriptable_value.py | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index 7ec0b55..46535d2 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -866,6 +866,9 @@ accessed. Python regular expressions are accepted.'} node=node.value) return + if is_inside_abstract_class(node): + return + inferred = safe_infer(node.value) if inferred is None or inferred is astroid.YES: return 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 -- cgit v1.2.1