forked from VimPlug/jedi
Replacing the types list with a types set. Some tests are failing, though.
This commit is contained in:
+17
-16
@@ -26,13 +26,14 @@ COMPARISON_OPERATORS = {
|
||||
def _literals_to_types(evaluator, result):
|
||||
# Changes literals ('a', 1, 1.0, etc) to its type instances (str(),
|
||||
# int(), float(), etc).
|
||||
result = list(result)
|
||||
for i, r in enumerate(result):
|
||||
if is_literal(r):
|
||||
# Literals are only valid as long as the operations are
|
||||
# correct. Otherwise add a value-free instance.
|
||||
cls = builtin.get_by_name(r.name.get_code())
|
||||
result[i] = evaluator.execute(cls)[0]
|
||||
return list(set(result))
|
||||
result[i] = list(evaluator.execute(cls))[0]
|
||||
return set(result)
|
||||
|
||||
|
||||
def calculate_children(evaluator, children):
|
||||
@@ -64,21 +65,21 @@ def calculate_children(evaluator, children):
|
||||
|
||||
|
||||
def calculate(evaluator, left_result, operator, right_result):
|
||||
result = []
|
||||
result = set()
|
||||
if not left_result or not right_result:
|
||||
# illegal slices e.g. cause left/right_result to be None
|
||||
result = (left_result or []) + (right_result or [])
|
||||
result = (left_result or set()) | (right_result or set())
|
||||
result = _literals_to_types(evaluator, result)
|
||||
else:
|
||||
# I don't think there's a reasonable chance that a string
|
||||
# operation is still correct, once we pass something like six
|
||||
# objects.
|
||||
if len(left_result) * len(right_result) > 6:
|
||||
result = _literals_to_types(evaluator, left_result + right_result)
|
||||
result = _literals_to_types(evaluator, left_result | right_result)
|
||||
else:
|
||||
for left in left_result:
|
||||
for right in right_result:
|
||||
result += _element_calculate(evaluator, left, operator, right)
|
||||
result |= _element_calculate(evaluator, left, operator, right)
|
||||
return result
|
||||
|
||||
|
||||
@@ -130,21 +131,21 @@ def _element_calculate(evaluator, left, operator, right):
|
||||
if operator == '*':
|
||||
# for iterables, ignore * operations
|
||||
if isinstance(left, iterable.Array) or is_string(left):
|
||||
return [left]
|
||||
return set([left])
|
||||
elif isinstance(right, iterable.Array) or is_string(right):
|
||||
return [right]
|
||||
return set([right])
|
||||
elif operator == '+':
|
||||
if l_is_num and r_is_num or is_string(left) and is_string(right):
|
||||
return [create(evaluator, left.obj + right.obj)]
|
||||
return set([create(evaluator, left.obj + right.obj)])
|
||||
elif _is_tuple(left) and _is_tuple(right) or _is_list(left) and _is_list(right):
|
||||
return [iterable.MergedArray(evaluator, (left, right))]
|
||||
return set([iterable.MergedArray(evaluator, (left, right))])
|
||||
elif operator == '-':
|
||||
if l_is_num and r_is_num:
|
||||
return [create(evaluator, left.obj - right.obj)]
|
||||
return set([create(evaluator, left.obj - right.obj)])
|
||||
elif operator == '%':
|
||||
# With strings and numbers the left type typically remains. Except for
|
||||
# `int() % float()`.
|
||||
return [left]
|
||||
return set([left])
|
||||
elif operator in COMPARISON_OPERATORS:
|
||||
operation = COMPARISON_OPERATORS[operator]
|
||||
if isinstance(left, CompiledObject) and isinstance(right, CompiledObject):
|
||||
@@ -153,12 +154,12 @@ def _element_calculate(evaluator, left, operator, right):
|
||||
right = right.obj
|
||||
|
||||
try:
|
||||
return [keyword_from_value(operation(left, right))]
|
||||
return set([keyword_from_value(operation(left, right))])
|
||||
except TypeError:
|
||||
# Could be True or False.
|
||||
return [true_obj, false_obj]
|
||||
return set([true_obj, false_obj])
|
||||
elif operator == 'in':
|
||||
return []
|
||||
return set()
|
||||
|
||||
def check(obj):
|
||||
"""Checks if a Jedi object is either a float or an int."""
|
||||
@@ -171,4 +172,4 @@ def _element_calculate(evaluator, left, operator, right):
|
||||
analysis.add(evaluator, 'type-error-operation', operator,
|
||||
message % (left, right))
|
||||
|
||||
return [left, right]
|
||||
return set([left, right])
|
||||
|
||||
Reference in New Issue
Block a user