1
0
forked from VimPlug/jedi

1 + '1' TypeErrors are now detected, but not shown in the right place

This commit is contained in:
Dave Halter
2014-07-22 10:44:56 +02:00
parent 52bbedd4a8
commit 50ceef6e09
2 changed files with 11 additions and 2 deletions

View File

@@ -17,7 +17,8 @@ CODES = {
'type-error-keyword-argument': (7, TypeError, None), 'type-error-keyword-argument': (7, TypeError, None),
'type-error-multiple-values': (8, TypeError, None), 'type-error-multiple-values': (8, TypeError, None),
'type-error-star-star': (9, TypeError, None), 'type-error-star-star': (9, TypeError, None),
'type-error-star': (9, TypeError, None), 'type-error-star': (10, TypeError, None),
'type-error-operation': (11, TypeError, None),
} }

View File

@@ -7,6 +7,7 @@ from jedi.parser import representation as pr
from jedi import debug from jedi import debug
from jedi.common import PushBackIterator from jedi.common import PushBackIterator
from jedi.evaluate.compiled import CompiledObject, create, builtin from jedi.evaluate.compiled import CompiledObject, create, builtin
from jedi.evaluate import analysis
class PythonGrammar(object): class PythonGrammar(object):
@@ -253,10 +254,17 @@ def _element_calculate(evaluator, left, operator, right):
elif isinstance(right, iterable.Array) or _is_string(right): elif isinstance(right, iterable.Array) or _is_string(right):
return [right] return [right]
elif operator == '+': elif operator == '+':
if _is_number(left) and _is_number(right) or _is_string(left) and _is_string(right): l_is_num = _is_number(left)
r_is_num = _is_number(right)
if l_is_num and r_is_num or _is_string(left) and _is_string(right):
return [create(evaluator, left.obj + right.obj)] return [create(evaluator, left.obj + right.obj)]
elif _is_tuple(left) and _is_tuple(right) or _is_list(left) and _is_list(right): elif _is_tuple(left) and _is_tuple(right) or _is_list(left) and _is_list(right):
return [iterable.MergedArray(evaluator, (left, right))] return [iterable.MergedArray(evaluator, (left, right))]
# Static analysis, one is a number, the other one is not.
elif l_is_num != r_is_num:
message = "TypeError: unsupported operand type(s) for +: %s and %s"
analysis.add(evaluator, 'type-error-operation', right,
message % (left, right))
elif operator == '-': elif operator == '-':
if _is_number(left) and _is_number(right): if _is_number(left) and _is_number(right):
return [create(evaluator, left.obj - right.obj)] return [create(evaluator, left.obj - right.obj)]