Don't warn on addition of an int literal plus an unknown int number.

This commit is contained in:
Dave Halter
2014-07-22 16:44:10 +02:00
parent f7c8c43fbc
commit 5e9d9573d5
2 changed files with 10 additions and 2 deletions

View File

@@ -261,7 +261,7 @@ def _is_list(obj):
def _element_calculate(evaluator, left, operator, right): def _element_calculate(evaluator, left, operator, right):
from jedi.evaluate import iterable from jedi.evaluate import iterable, representation as er
l_is_num = _is_number(left) l_is_num = _is_number(left)
r_is_num = _is_number(right) r_is_num = _is_number(right)
if operator == '*': if operator == '*':
@@ -283,8 +283,13 @@ def _element_calculate(evaluator, left, operator, right):
# `int() % float()`. # `int() % float()`.
return [left] return [left]
def check(obj):
"""Checks if a Jedi object is either a float or an int."""
return isinstance(obj, er.Instance) and obj.name in ('int', 'float')
# Static analysis, one is a number, the other one is not. # Static analysis, one is a number, the other one is not.
if operator in ['+', '-'] and l_is_num != r_is_num: if operator in ('+', '-') and l_is_num != r_is_num \
and not (check(left) or check(right)):
message = "TypeError: unsupported operand type(s) for +: %s and %s" message = "TypeError: unsupported operand type(s) for +: %s and %s"
analysis.add(evaluator, 'type-error-operation', operator, analysis.add(evaluator, 'type-error-operation', operator,
message % (left, right)) message % (left, right))

View File

@@ -6,3 +6,6 @@
1 - '1' 1 - '1'
-1 - - 1 -1 - - 1
-1 - int()
int() - float()
float() - 3.0