forked from VimPlug/jedi
Move eval_or_test away from precedence module.
This commit is contained in:
@@ -4,7 +4,6 @@ Handles operator precedence.
|
|||||||
import operator as op
|
import operator as op
|
||||||
|
|
||||||
from jedi._compatibility import unicode
|
from jedi._compatibility import unicode
|
||||||
from jedi import debug
|
|
||||||
from jedi.evaluate.compiled import CompiledObject, create, builtin_from_name
|
from jedi.evaluate.compiled import CompiledObject, create, builtin_from_name
|
||||||
from jedi.evaluate import analysis
|
from jedi.evaluate import analysis
|
||||||
from jedi.evaluate.context import ContextSet, NO_CONTEXTS, iterator_to_context_set
|
from jedi.evaluate.context import ContextSet, NO_CONTEXTS, iterator_to_context_set
|
||||||
@@ -37,34 +36,6 @@ def literals_to_types(evaluator, result):
|
|||||||
return new_result
|
return new_result
|
||||||
|
|
||||||
|
|
||||||
def calculate_children(evaluator, context, children):
|
|
||||||
"""
|
|
||||||
Calculate a list of children with operators.
|
|
||||||
"""
|
|
||||||
iterator = iter(children)
|
|
||||||
types = context.eval_node(next(iterator))
|
|
||||||
for operator in iterator:
|
|
||||||
right = next(iterator)
|
|
||||||
if operator.type == 'comp_op': # not in / is not
|
|
||||||
operator = ' '.join(c.value for c in operator.children)
|
|
||||||
|
|
||||||
# handle lazy evaluation of and/or here.
|
|
||||||
if operator in ('and', 'or'):
|
|
||||||
left_bools = set(left.py__bool__() for left in types)
|
|
||||||
if left_bools == set([True]):
|
|
||||||
if operator == 'and':
|
|
||||||
types = context.eval_node(right)
|
|
||||||
elif left_bools == set([False]):
|
|
||||||
if operator != 'and':
|
|
||||||
types = context.eval_node(right)
|
|
||||||
# Otherwise continue, because of uncertainty.
|
|
||||||
else:
|
|
||||||
types = calculate(evaluator, context, types, operator,
|
|
||||||
context.eval_node(right))
|
|
||||||
debug.dbg('calculate_children types %s', types)
|
|
||||||
return types
|
|
||||||
|
|
||||||
|
|
||||||
def calculate(evaluator, context, left_contexts, operator, right_contexts):
|
def calculate(evaluator, context, left_contexts, operator, right_contexts):
|
||||||
if not left_contexts or not right_contexts:
|
if not left_contexts or not right_contexts:
|
||||||
# illegal slices e.g. cause left/right_result to be None
|
# illegal slices e.g. cause left/right_result to be None
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ def eval_node(context, element):
|
|||||||
elif typ == 'annassign':
|
elif typ == 'annassign':
|
||||||
return pep0484._evaluate_for_annotation(context, element.children[1])
|
return pep0484._evaluate_for_annotation(context, element.children[1])
|
||||||
else:
|
else:
|
||||||
return precedence.calculate_children(evaluator, context, element.children)
|
return eval_or_test(context, element)
|
||||||
|
|
||||||
|
|
||||||
def eval_trailer(context, base_contexts, trailer):
|
def eval_trailer(context, base_contexts, trailer):
|
||||||
@@ -255,3 +255,28 @@ def _eval_expr_stmt(context, stmt, seek_name=None):
|
|||||||
context_set = precedence.calculate(context.evaluator, context, left, operator, context_set)
|
context_set = precedence.calculate(context.evaluator, context, left, operator, context_set)
|
||||||
debug.dbg('eval_expr_stmt result %s', context_set)
|
debug.dbg('eval_expr_stmt result %s', context_set)
|
||||||
return context_set
|
return context_set
|
||||||
|
|
||||||
|
|
||||||
|
def eval_or_test(context, or_test):
|
||||||
|
iterator = iter(or_test.children)
|
||||||
|
types = context.eval_node(next(iterator))
|
||||||
|
for operator in iterator:
|
||||||
|
right = next(iterator)
|
||||||
|
if operator.type == 'comp_op': # not in / is not
|
||||||
|
operator = ' '.join(c.value for c in operator.children)
|
||||||
|
|
||||||
|
# handle lazy evaluation of and/or here.
|
||||||
|
if operator in ('and', 'or'):
|
||||||
|
left_bools = set(left.py__bool__() for left in types)
|
||||||
|
if left_bools == set([True]):
|
||||||
|
if operator == 'and':
|
||||||
|
types = context.eval_node(right)
|
||||||
|
elif left_bools == set([False]):
|
||||||
|
if operator != 'and':
|
||||||
|
types = context.eval_node(right)
|
||||||
|
# Otherwise continue, because of uncertainty.
|
||||||
|
else:
|
||||||
|
types = precedence.calculate(context.evaluator, context, types, operator,
|
||||||
|
context.eval_node(right))
|
||||||
|
debug.dbg('calculate_children types %s', types)
|
||||||
|
return types
|
||||||
|
|||||||
Reference in New Issue
Block a user