summaryrefslogtreecommitdiff
path: root/pylint/checkers/utils.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2015-11-26 17:18:16 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2015-11-26 17:18:16 +0200
commit0c7dc2248c66da8d8884985ec5d96f2d243b1849 (patch)
treec147f8d0cc1690bfd777fd4044d946173bbc07a2 /pylint/checkers/utils.py
parente3aa096710619f7b4647b9656649f90b29fe6eba (diff)
downloadpylint-0c7dc2248c66da8d8884985ec5d96f2d243b1849.tar.gz
Added a new warning, 'unsupported-delete-operation'
It is emitted when item deletion is tried on an object which doesn't have this ability. Closes issue #592.
Diffstat (limited to 'pylint/checkers/utils.py')
-rw-r--r--pylint/checkers/utils.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index ba396b0..0d6a488 100644
--- a/pylint/checkers/utils.py
+++ b/pylint/checkers/utils.py
@@ -44,6 +44,7 @@ ITER_METHOD = '__iter__'
NEXT_METHOD = 'next' if six.PY2 else '__next__'
GETITEM_METHOD = '__getitem__'
SETITEM_METHOD = '__setitem__'
+DELITEM_METHOD = '__delitem__'
CONTAINS_METHOD = '__contains__'
KEYS_METHOD = 'keys'
@@ -627,6 +628,10 @@ def _supports_setitem_protocol(value):
return _hasattr(value, SETITEM_METHOD)
+def _supports_delitem_protocol(value):
+ return _hasattr(value, DELITEM_METHOD)
+
+
def _is_abstract_class_name(name):
lname = name.lower()
is_mixin = lname.endswith('mixin')
@@ -685,6 +690,10 @@ def supports_setitem(value):
return _supports_protocol(value, _supports_setitem_protocol)
+def supports_delitem(value):
+ return _supports_protocol(value, _supports_delitem_protocol)
+
+
# TODO(cpopa): deprecate these or leave them as aliases?
def safe_infer(node, context=None):
"""Return the inferred value for the given node.