diff options
author | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2015-06-30 01:31:08 +0300 |
---|---|---|
committer | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2015-06-30 01:31:08 +0300 |
commit | 82b63d329b8722d49fe8da38e94209bda2604796 (patch) | |
tree | 9f9ff1dadd73e5b656aa9962a5b97acdacda5107 /pylint/checkers/typecheck.py | |
parent | c50c1c897678a2b48cd0b55f1b0b24cdfbc412f2 (diff) | |
download | pylint-82b63d329b8722d49fe8da38e94209bda2604796.tar.gz |
Add a new error, 'unsupported-binary-operation'.
This error is emitted when two a binary arithmetic operation is
executed between two objects which don't support it
(a number plus a string for instance).
Diffstat (limited to 'pylint/checkers/typecheck.py')
-rw-r--r-- | pylint/checkers/typecheck.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index 6c34eaf..c4679dc 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -92,6 +92,10 @@ MSGS = { 'invalid-unary-operand-type', 'Emitted when an unary operand is used on an object which does not ' 'support this type of operation'), + 'E1131': ('%s', + 'unsupported-binary-operation', + 'Emitted when a binary arithmetic operation between two ' + 'operands is not supported.'), } # builtin sequence types in Python 2 and 3. @@ -720,6 +724,22 @@ accessed. Python regular expressions are accepted.'} self.add_message('invalid-unary-operand-type', args=str(error), node=node) + @check_messages('unsupported-binary-operation') + def visit_binop(self, node): + """Detect TypeErrors for binary arithmetic operands.""" + self._check_binop_errors(node) + + @check_messages('unsupported-binary-operation') + def visit_augassign(self, node): + """Detect TypeErrors for augmented binary arithmetic operands.""" + self._check_binop_errors(node) + + def _check_binop_errors(self, node): + for error in node.type_errors(): + # Let the error customize its output. + self.add_message('unsupported-binary-operation', + args=str(error), node=node) + def register(linter): """required method to auto register this checker """ |