diff --git a/jedi/evaluate/precedence.py b/jedi/evaluate/precedence.py index 9736e7a6..39e4afc9 100644 --- a/jedi/evaluate/precedence.py +++ b/jedi/evaluate/precedence.py @@ -261,7 +261,7 @@ def _is_list(obj): 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) r_is_num = _is_number(right) if operator == '*': @@ -283,8 +283,13 @@ def _element_calculate(evaluator, left, operator, right): # `int() % float()`. 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. - 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" analysis.add(evaluator, 'type-error-operation', operator, message % (left, right)) diff --git a/test/static_analysis/operations.py b/test/static_analysis/operations.py index e0827637..71fbd230 100644 --- a/test/static_analysis/operations.py +++ b/test/static_analysis/operations.py @@ -6,3 +6,6 @@ 1 - '1' -1 - - 1 +-1 - int() +int() - float() +float() - 3.0