1
0
forked from VimPlug/jedi

Move eval_or_test away from precedence module.

This commit is contained in:
Dave Halter
2017-09-27 18:51:53 +02:00
parent 08a48672bc
commit d0939f0449
2 changed files with 26 additions and 30 deletions

View File

@@ -4,7 +4,6 @@ Handles operator precedence.
import operator as op
from jedi._compatibility import unicode
from jedi import debug
from jedi.evaluate.compiled import CompiledObject, create, builtin_from_name
from jedi.evaluate import analysis
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
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):
if not left_contexts or not right_contexts:
# illegal slices e.g. cause left/right_result to be None

View File

@@ -107,7 +107,7 @@ def eval_node(context, element):
elif typ == 'annassign':
return pep0484._evaluate_for_annotation(context, element.children[1])
else:
return precedence.calculate_children(evaluator, context, element.children)
return eval_or_test(context, element)
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)
debug.dbg('eval_expr_stmt result %s', 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