summaryrefslogtreecommitdiff
path: root/pylint/checkers/utils.py
diff options
context:
space:
mode:
authorDmitry Pribysh <dmand@yandex.ru>2015-11-03 17:37:20 +0300
committerDmitry Pribysh <dmand@yandex.ru>2015-11-03 17:37:20 +0300
commitf93a5c6dba7014e11ab0300a40eef321dca3bb5a (patch)
tree36aa81c7df16dbf394cc9e62da3697542318583a /pylint/checkers/utils.py
parent9ec0cfac7937cdf56519f033c074e8f6b4cf1ccf (diff)
downloadpylint-f93a5c6dba7014e11ab0300a40eef321dca3bb5a.tar.gz
Add checker for unsubscriptable values used in subscript expression.
Fixes issue #561.
Diffstat (limited to 'pylint/checkers/utils.py')
-rw-r--r--pylint/checkers/utils.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index 5f9c227..a3c8c01 100644
--- a/pylint/checkers/utils.py
+++ b/pylint/checkers/utils.py
@@ -618,6 +618,10 @@ def _supports_iteration_protocol(value):
return _hasattr(value, ITER_METHOD) or _hasattr(value, GETITEM_METHOD)
+def _supports_subscript_protocol(value):
+ return _hasattr(value, GETITEM_METHOD)
+
+
def _is_abstract_class_name(name):
lname = name.lower()
is_mixin = lname.endswith('mixin')
@@ -687,6 +691,20 @@ def supports_membership_test(value):
return is_iterable(value)
+def supports_subscript(value):
+ if isinstance(value, astroid.ClassDef):
+ if not helpers.has_known_bases(value):
+ return False
+ meta = value.metaclass()
+ if meta is not None and _supports_subscript_protocol(meta):
+ return True
+ if isinstance(value, astroid.Instance):
+ if not helpers.has_known_bases(value):
+ return True
+ if _supports_subscript_protocol(value):
+ return True
+ return False
+
# TODO(cpopa): deprecate these or leave them as aliases?
safe_infer = astroid.helpers.safe_infer
has_known_bases = astroid.helpers.has_known_bases