From 0c7dc2248c66da8d8884985ec5d96f2d243b1849 Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Thu, 26 Nov 2015 17:18:16 +0200 Subject: 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. --- pylint/checkers/utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'pylint/checkers/utils.py') 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. -- cgit v1.2.1