mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-20 12:31:14 +08:00
string additions also work now - be prepared #24!
This commit is contained in:
@@ -200,6 +200,6 @@ def _element_calculate(left, operator, right):
|
|||||||
if isinstance(left, iterable.Array) or is_string(left):
|
if isinstance(left, iterable.Array) or is_string(left):
|
||||||
return [left]
|
return [left]
|
||||||
elif operator == '+':
|
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 [create(left.obj + right.obj)]
|
||||||
return [left, right]
|
return [left, right]
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
Test Jedi's operation understanding. Jedi should understand simple additions,
|
Test Jedi's operation understanding. Jedi should understand simple additions,
|
||||||
multiplications, etc.
|
multiplications, etc.
|
||||||
"""
|
"""
|
||||||
|
# -----------------
|
||||||
|
# numbers
|
||||||
|
# -----------------
|
||||||
x = [1, 'a', 1.0]
|
x = [1, 'a', 1.0]
|
||||||
|
|
||||||
#? int() str() float()
|
#? int() str() float()
|
||||||
@@ -23,3 +26,29 @@ constant = 1
|
|||||||
|
|
||||||
#? float()
|
#? float()
|
||||||
x[calculate(1)]
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user