diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2015-11-26 15:35:03 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2015-11-26 15:35:03 +0200 |
commit | e3aa096710619f7b4647b9656649f90b29fe6eba (patch) | |
tree | 171f7a8a9d2113786bf200f14a65ba136daf3f05 /pylint/checkers/utils.py | |
parent | 0b4bcb2a8b3d2aa1c90b7369f727532237e153c5 (diff) | |
download | pylint-e3aa096710619f7b4647b9656649f90b29fe6eba.tar.gz |
Added a new warning, 'unsupported-assignment-operation'
This is emitted when item assignment is tried on an object which doesn't
have this ability. Closes issue #591.
Diffstat (limited to 'pylint/checkers/utils.py')
-rw-r--r-- | pylint/checkers/utils.py | 15 |
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? |