diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | pylint/checkers/typecheck.py | 13 |
2 files changed, 19 insertions, 0 deletions
@@ -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 """ |