forked from VimPlug/jedi
plus on numbers is now basically working
This commit is contained in:
@@ -6,7 +6,7 @@ from jedi._compatibility import unicode
|
|||||||
from jedi.parser import representation as pr
|
from jedi.parser import representation as pr
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.common import PushBackIterator
|
from jedi.common import PushBackIterator
|
||||||
from jedi.evaluate.compiled import CompiledObject
|
from jedi.evaluate.compiled import CompiledObject, create
|
||||||
from jedi.evaluate import iterable
|
from jedi.evaluate import iterable
|
||||||
|
|
||||||
|
|
||||||
@@ -175,12 +175,31 @@ def _check_operator(iterator, priority=PythonGrammar.LOWEST_PRIORITY):
|
|||||||
return left
|
return left
|
||||||
|
|
||||||
|
|
||||||
def calculate(left, operator, right):
|
def calculate(left_result, operator, right_result):
|
||||||
|
if not left_result or not right_result:
|
||||||
|
return left_result + right_result
|
||||||
|
|
||||||
|
result = []
|
||||||
|
for left in left_result:
|
||||||
|
for right in right_result:
|
||||||
|
result += _element_calculate(left, operator, right)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def _element_calculate(left, operator, right):
|
||||||
|
def is_string(obj):
|
||||||
|
return isinstance(obj, CompiledObject) \
|
||||||
|
and isinstance(obj.obj, (str, unicode))
|
||||||
|
|
||||||
|
def is_number(obj):
|
||||||
|
return isinstance(obj, CompiledObject) \
|
||||||
|
and isinstance(obj.obj, (int, float))
|
||||||
|
|
||||||
if operator == '*':
|
if operator == '*':
|
||||||
if [l for l in left if isinstance(l, iterable.Array)
|
# for iterables, ignore * operations
|
||||||
or isinstance(l, CompiledObject)
|
if isinstance(left, iterable.Array) or is_string(left):
|
||||||
and isinstance(l.obj, (str, unicode))]:
|
return [left]
|
||||||
# if it is an iterable, ignore * operations
|
elif operator == '+':
|
||||||
return left
|
if is_number(left) and is_number(right):
|
||||||
return left + right
|
return [create(left.obj + right.obj)]
|
||||||
|
return [left, right]
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ x = [1, 'a', 1.0]
|
|||||||
#? int() str() float()
|
#? int() str() float()
|
||||||
x[12]
|
x[12]
|
||||||
|
|
||||||
#? str()
|
#? float()
|
||||||
x[1 + 1]
|
x[1 + 1]
|
||||||
|
|
||||||
index = 0 + 2
|
index = 0 + 1
|
||||||
|
|
||||||
#? float()
|
#? str()
|
||||||
x[index]
|
x[index]
|
||||||
|
|
||||||
|
|
||||||
@@ -22,4 +22,4 @@ def calculate(number):
|
|||||||
constant = 1
|
constant = 1
|
||||||
|
|
||||||
#? float()
|
#? float()
|
||||||
x[calculate(2)]
|
x[calculate(1)]
|
||||||
|
|||||||
Reference in New Issue
Block a user