Project Name: davidhalter+jedi
Language: Python
Statement Type: API

Source Code:
def infer_node(context, element):
    if isinstance(context, CompForContext):
        return _infer_node(context, element)

    if_stmt = element
    while if_stmt is not None:
        if_stmt = if_stmt.parent
        if if_stmt.type in ('if_stmt', 'for_stmt'):
            break
        if parser_utils.is_scope(if_stmt):
            if_stmt = None
            break
    predefined_if_name_dict = context.predefined_names.get(if_stmt)
    # TODO there's a lot of issues with this one. We actually should do
    # this in a different way. Caching should only be active in certain
    # cases and this all sucks.
    if predefined_if_name_dict is None and if_stmt \
            and if_stmt.type == 'if_stmt' and context.inference_state.is_analysis:
        if_stmt_test = if_stmt.children[1]
        name_dicts = [{}]
        # If we already did a check, we don't want to do it again -> If
        # value.predefined_names is filled, we stop.
        # We don't want to check the if stmt itself, it's just about
        # the content.
        if element.start_pos > if_stmt_test.end_pos:
            # Now we need to check if the names in the if_stmt match the
            # names in the suite.
            if_names = get_names_of_node(if_stmt_test)
            element_names = get_names_of_node(element)
            str_element_names = [e.value for e in element_names]
            if any(i.value in str_element_names for i in if_names):
                for if_name in if_names:
                    definitions = context.inference_state.infer(context, if_name)
                    # Every name that has multiple different definitions
                    # causes the complexity to rise. The complexity should
                    # never fall below 1.
                    if len(definitions) > 1:
                        if len(name_dicts) * len(definitions) > 16:
                            debug.dbg('Too many options for if branch inference %s.', if_stmt)
                            # There's only a certain amount of branches
                            # Jedi can infer, otherwise it will take to
                            # long.
                            name_dicts = [{}]
                            break

                        original_name_dicts = list(name_dicts)
                        name_dicts = []
                        for definition in definitions:
                            new_name_dicts = list(original_name_dicts)
                            for i, name_dict in enumerate(new_name_dicts):
                                new_name_dicts[i] = name_dict.copy()
                                new_name_dicts[i][if_name.value] = ValueSet([definition])

                            name_dicts += new_name_dicts
                    else:
                        for name_dict in name_dicts:
                            name_dict[if_name.value] = definitions
        if len(name_dicts) > 1:
            result = NO_VALUES
            for name_dict in name_dicts:
                with context.predefine_names(if_stmt, name_dict):
                    result |= _infer_node(context, element)
            return result
        else:
            return _infer_node_if_inferred(context, element)
    else:
        if predefined_if_name_dict:
            return _infer_node(context, element)
        else:
            return _infer_node_if_inferred(context, element)

infer_node(context=ModuleContext(<ModuleValue: __main__@2-8 is_stub=False>), element=PythonNode(test, [<Name: f@8,11>, <Keyword: if>, PythonNode(atom_expr, [<Name: random@8,16>, PythonNode(trailer, [<Operator: .>, <Name: choice@8,23>]), PythonNode(trailer, [<Operator: (>, PythonNode(atom, [<Operator: [>, PythonNode(testlist_comp, [<Number: 0>, <Operator: ,>, <Number: 1>]), <Operator: ]>]), <Operator: )>])]), <Keyword: else>, <Name: C@8,42>]))

Selected Statement: predefined_if_name_dict = context.predefined_names.get(if_stmt)

Function Input:
context: ModuleContext(<ModuleValue: __main__@2-8 is_stub=False>)
element: PythonNode(test, [<Name: f@8,11>, <Keyword: if>, PythonNode(atom_expr, [<Name: random@8,16>, PythonNode(trailer, [<Operator: .>, <Name: choice@8,23>]), PythonNode(trailer, [<Operator: (>, PythonNode(atom, [<Operator: [>, PythonNode(testlist_comp, [<Number: 0>, <Operator: ,>, <Number: 1>]), <Operator: ]>]), <Operator: )>])]), <Keyword: else>, <Name: C@8,42>])

Variable Values Before Statement:
if_stmt: None

Value After Statement Execution: None

Variable States During Runtime (line, value):
context: 1
ModuleContext(<ModuleValue: __main__@2-8 is_stub=False>)
element: 1
PythonNode(test, [<Name: f@8,11>, <Keyword: if>, PythonNode(atom_expr, [<Name: random@8,16>, PythonNode(trailer, [<Operator: .>, <Name: choice@8,23>]), PythonNode(trailer, [<Operator: (>, PythonNode(atom, [<Operator: [>, PythonNode(testlist_comp, [<Number: 0>, <Operator: ,>, <Number: 1>]), <Operator: ]>]), <Operator: )>])]), <Keyword: else>, <Name: C@8,42>])
if_stmt: 5
PythonNode(test, [<Name: f@8,11>, <Keyword: if>, PythonNode(atom_expr, [<Name: random@8,16>, PythonNode(trailer, [<Operator: .>, <Name: choice@8,23>]), PythonNode(trailer, [<Operator: (>, PythonNode(atom, [<Operator: [>, PythonNode(testlist_comp, [<Number: 0>, <Operator: ,>, <Number: 1>]), <Operator: ]>]), <Operator: )>])]), <Keyword: else>, <Name: C@8,42>])
7
<ExprStmt: variable = f if random.choice([0,1]) else C@8,0>
7
<Module: @2-8>
11
None
predefined_if_name_dict: 13
None