From b22c9c96f21b08188925d434189047c838c1d9c3 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 9 Mar 2014 12:36:17 +0100 Subject: [PATCH] string additions also work now - be prepared #24! --- jedi/evaluate/precedence.py | 2 +- test/completion/operators.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/jedi/evaluate/precedence.py b/jedi/evaluate/precedence.py index 44d2a302..c7a10ef0 100644 --- a/jedi/evaluate/precedence.py +++ b/jedi/evaluate/precedence.py @@ -200,6 +200,6 @@ def _element_calculate(left, operator, right): if isinstance(left, iterable.Array) or is_string(left): return [left] elif operator == '+': - if is_number(left) and is_number(right): + if is_number(left) and is_number(right) or is_string(left) and is_string(right): return [create(left.obj + right.obj)] return [left, right] diff --git a/test/completion/operators.py b/test/completion/operators.py index 94987c2b..99340bf9 100644 --- a/test/completion/operators.py +++ b/test/completion/operators.py @@ -2,6 +2,9 @@ Test Jedi's operation understanding. Jedi should understand simple additions, multiplications, etc. """ +# ----------------- +# numbers +# ----------------- x = [1, 'a', 1.0] #? int() str() float() @@ -23,3 +26,29 @@ constant = 1 #? float() x[calculate(1)] + +def calculate(number): + return number + constant + +# ----------------- +# strings +# ----------------- + +class FooBar(object): + muahaha = 3.0 + raboof = 'fourtytwo' + +x = 'mua' + 'ha' + +#? float() +getattr(FooBar, x + 'ha') + + +# github #24 +target = u'' +for char in reversed(['f', 'o', 'o', 'b', 'a', 'r']): + target += char + +answer = getattr(FooBar, target) +##? str() +answer