summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2015-06-13 19:24:32 +0300
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2015-06-13 19:24:32 +0300
commitdbe36b27eb863a58693ad04f0d28b9767a8bdaad (patch)
tree7d260345eced8f034bc3fba811c53db5955d7b52
parent9394f82f0df0a55a040d38a8d908eb924d848792 (diff)
downloadpylint-dbe36b27eb863a58693ad04f0d28b9767a8bdaad.tar.gz
Add a new error, 'invalid-unary-type-operand'.
This new error is emitted when an unary operand is used on something which doesn't support that operation (for instance, using the unary bitwise inversion operator on an instance which doesn't implement __invert__).
-rw-r--r--ChangeLog6
-rw-r--r--pylint/checkers/typecheck.py13
2 files changed, 19 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 29cbc87..e6204fc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -155,6 +155,12 @@ ChangeLog for Pylint
if pylintrc is not found. Dotted pylintrc files will not be searched
in the parents of the current folder, as it is done for pylintrc.
+ * Add a new error, 'invalid-unary-type-operand', emitted when
+ an unary operand is used on something which doesn't support that
+ operation (for instance, using the unary bitwise inversion operator
+ on an instance which doesn't implement __invert__).
+
+
2015-03-14 -- 1.4.3
diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py
index c7c2200..5dd3ff9 100644
--- a/pylint/checkers/typecheck.py
+++ b/pylint/checkers/typecheck.py
@@ -88,6 +88,10 @@ MSGS = {
'not-context-manager',
'Used when an instance in a with statement doesn\'t implement '
'the context manager protocol(__enter__/__exit__).'),
+ 'E1130': ('%s',
+ 'invalid-unary-operand-type',
+ 'Emitted when an unary operand is used on an object which does not '
+ 'support this type of operation'),
}
# builtin sequence types in Python 2 and 3.
@@ -702,6 +706,15 @@ accessed. Python regular expressions are accepted.'}
self.add_message('not-context-manager',
node=node, args=(infered.name, ))
+ @check_messages('invalid-unary-operand-type')
+ def visit_unaryop(self, node):
+ """Detect TypeErrors for unary operands."""
+
+ for error in node.type_errors():
+ # Let the error customize its output.
+ self.add_message('invalid-unary-operand-type',
+ args=str(error), node=node)
+
def register(linter):
"""required method to auto register this checker """