From 77baabb93b73ecde5d5d4dad2d6d3b33a0c15e71 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Mon, 19 May 2014 13:26:12 +0200 Subject: [PATCH] % operation returned both left and right side, but only the left side is really important. --- jedi/evaluate/precedence.py | 4 ++++ test/static_analysis/attribute_error.py | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/jedi/evaluate/precedence.py b/jedi/evaluate/precedence.py index 514dfa69..437ac431 100644 --- a/jedi/evaluate/precedence.py +++ b/jedi/evaluate/precedence.py @@ -244,4 +244,8 @@ def _element_calculate(evaluator, left, operator, right): elif operator == '-': if _is_number(left) and _is_number(right): return [create(evaluator, left.obj - right.obj)] + elif operator == '%': + # With strings and numbers the left type typically remains. Except for + # `int() % float()`. + return [left] return [left, right] diff --git a/test/static_analysis/attribute_error.py b/test/static_analysis/attribute_error.py index e6b50b96..b7c07855 100644 --- a/test/static_analysis/attribute_error.py +++ b/test/static_analysis/attribute_error.py @@ -84,3 +84,13 @@ return_one(''.undefined_attribute) @undefined_decorator def func(): return 1 + +# ----------------- +# operators +# ----------------- + +string = '%s %s' % (1, 2) + +# Shouldn't raise an error, because `string` is really just a string, not an +# array or something. +string.upper