forked from VimPlug/jedi
1 + '1' TypeErrors are now detected, but not shown in the right place
This commit is contained in:
@@ -17,7 +17,8 @@ CODES = {
|
||||
'type-error-keyword-argument': (7, TypeError, None),
|
||||
'type-error-multiple-values': (8, 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),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ from jedi.parser import representation as pr
|
||||
from jedi import debug
|
||||
from jedi.common import PushBackIterator
|
||||
from jedi.evaluate.compiled import CompiledObject, create, builtin
|
||||
from jedi.evaluate import analysis
|
||||
|
||||
|
||||
class PythonGrammar(object):
|
||||
@@ -253,10 +254,17 @@ def _element_calculate(evaluator, left, operator, right):
|
||||
elif isinstance(right, iterable.Array) or _is_string(right):
|
||||
return [right]
|
||||
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)]
|
||||
elif _is_tuple(left) and _is_tuple(right) or _is_list(left) and _is_list(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 == '-':
|
||||
if _is_number(left) and _is_number(right):
|
||||
return [create(evaluator, left.obj - right.obj)]
|
||||
|
||||
Reference in New Issue
Block a user