diff --git a/jedi/evaluate/precedence.py b/jedi/evaluate/precedence.py index 7e054c05..54973777 100644 --- a/jedi/evaluate/precedence.py +++ b/jedi/evaluate/precedence.py @@ -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 diff --git a/jedi/evaluate/syntax_tree.py b/jedi/evaluate/syntax_tree.py index 240a1b14..84b6c0bf 100644 --- a/jedi/evaluate/syntax_tree.py +++ b/jedi/evaluate/syntax_tree.py @@ -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