summaryrefslogtreecommitdiff
path: root/pylint/checkers/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'pylint/checkers/utils.py')
-rw-r--r--pylint/checkers/utils.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index e24a034..ba396b0 100644
--- a/pylint/checkers/utils.py
+++ b/pylint/checkers/utils.py
@@ -43,6 +43,7 @@ ABC_METHODS = set(('abc.abstractproperty', 'abc.abstractmethod',
ITER_METHOD = '__iter__'
NEXT_METHOD = 'next' if six.PY2 else '__next__'
GETITEM_METHOD = '__getitem__'
+SETITEM_METHOD = '__setitem__'
CONTAINS_METHOD = '__contains__'
KEYS_METHOD = 'keys'
@@ -618,10 +619,14 @@ def _supports_iteration_protocol(value):
return _hasattr(value, ITER_METHOD) or _hasattr(value, GETITEM_METHOD)
-def _supports_subscript_protocol(value):
+def _supports_getitem_protocol(value):
return _hasattr(value, GETITEM_METHOD)
+def _supports_setitem_protocol(value):
+ return _hasattr(value, SETITEM_METHOD)
+
+
def _is_abstract_class_name(name):
lname = name.lower()
is_mixin = lname.endswith('mixin')
@@ -672,8 +677,12 @@ def supports_membership_test(value):
return supported or is_iterable(value)
-def supports_subscript(value):
- return _supports_protocol(value, _supports_subscript_protocol)
+def supports_getitem(value):
+ return _supports_protocol(value, _supports_getitem_protocol)
+
+
+def supports_setitem(value):
+ return _supports_protocol(value, _supports_setitem_protocol)
# TODO(cpopa): deprecate these or leave them as aliases?