Ejemplo n.º 1
0
def lambda_mutation(children, **_):
    from parso.python.tree import Name
    if len(children) != 4 or getattr(children[-1], 'value', '---') != 'None':
        return children[:3] + [
            Name(value=' None', start_pos=children[0].start_pos)
        ]
    else:
        return children[:3] + [
            Name(value=' 0', start_pos=children[0].start_pos)
        ]
Ejemplo n.º 2
0
def argument_mutation(children, context, **_):
    """
    :type context: Context
    """
    if len(context.stack) >= 3 and context.stack[-3].type in ('power',
                                                              'atom_expr'):
        stack_pos_of_power_node = -3
    elif len(context.stack) >= 4 and context.stack[-4].type in ('power',
                                                                'atom_expr'):
        stack_pos_of_power_node = -4
    else:
        return children

    power_node = context.stack[stack_pos_of_power_node]

    if power_node.children[0].type == 'name' and power_node.children[
            0].value in context.dict_synonyms:
        children = children[:]
        from parso.python.tree import Name
        c = children[0]
        if c.type == 'name':
            children[0] = Name(c.value + 'XX',
                               start_pos=c.start_pos,
                               prefix=c.prefix)

    return children
Ejemplo n.º 3
0
def argument_mutation(children, context, **_):
    """Mutate the arguments one by one from dict(a=b) to dict(aXXX=b).

    This is similar to the mutation of dict literals in the form {'a': b}.

    :type context: Context
    """
    if len(context.stack) >= 3 and context.stack[-3].type in ('power',
                                                              'atom_expr'):
        stack_pos_of_power_node = -3
    elif len(context.stack) >= 4 and context.stack[-4].type in ('power',
                                                                'atom_expr'):
        stack_pos_of_power_node = -4
    else:
        return

    power_node = context.stack[stack_pos_of_power_node]

    if power_node.children[0].type == 'name' and power_node.children[
            0].value in context.dict_synonyms:
        c = children[0]
        if c.type == 'name':
            children = children[:]
            children[0] = Name(c.value + 'XX',
                               start_pos=c.start_pos,
                               prefix=c.prefix)
            return children
Ejemplo n.º 4
0
    def handle_assignment(children):
        if getattr(children[2], 'value', '---') != 'None':
            x = ' None'
        else:
            x = ' ""'
        children = children[:]
        children[2] = Name(value=x, start_pos=children[2].start_pos)

        return children
Ejemplo n.º 5
0
    def handle_assignment(children):
        mutation_index = -1  # we mutate the last value to handle multiple assignement
        if getattr(children[mutation_index], 'value', '---') != 'None':
            x = ' None'
        else:
            x = ' ""'
        children = children[:]
        children[mutation_index] = Name(value=x, start_pos=children[mutation_index].start_pos)

        return children
Ejemplo n.º 6
0
    def handle_assignment(children):
        if getattr(children[2], 'value', '---') != 'None':
            x = ' None'
        else:
            x = ' 7'
        children = children[:]
        from parso.python.tree import Name
        children[2] = Name(value=x, start_pos=children[2].start_pos)

        return children
Ejemplo n.º 7
0
def expression_mutation(children, **_):
    assert children[1].type == 'operator'
    if children[1].value == '=':
        if getattr(children[2], 'value', '---') != 'None':
            x = ' None'
        else:
            x = ' 7'
        children = children[:]
        from parso.python.tree import Name
        children[2] = Name(value=x, start_pos=children[2].start_pos)

    return children
Ejemplo n.º 8
0
def trailer_mutation(children, **_):
    if len(children) == 3 and children[0].type == 'operator' and children[
            0].value == '[' and children[-1].type == 'operator' and children[
                -1].value == ']' and children[
                    0].parent.type == 'trailer' and children[
                        1].type == 'name' and children[1].value != 'None':
        # Something that looks like "foo[bar]"
        return [
            children[0],
            Name(value='None', start_pos=children[0].start_pos), children[-1]
        ]
    return children
Ejemplo n.º 9
0
def argument_mutation(children, context, **_):
    """
    :type context: Context
    """
    if context.stack[-3].type == 'power':
        stack_pos_of_power_node = -3
    elif context.stack[-4].type == 'power':
        stack_pos_of_power_node = -4
    else:
        stack_pos_of_power_node = None

    power_node = context.stack[stack_pos_of_power_node] if stack_pos_of_power_node is not None else None

    if power_node and power_node.children[0].type == 'name' and power_node.children[0].value in context.dict_synonyms:
        children = children[:]
        from parso.python.tree import Name
        c = children[0]
        children[0] = Name(c.value + 'XX', start_pos=c.start_pos, prefix=c.prefix)

    return children
Ejemplo n.º 10
0
def arglist_mutation(children, **_):
    if len(children) > 3 and children[
            0].type == 'name' and children[0].value != 'None':
        return [Name(value='None', start_pos=children[0].start_pos)
                ] + children[1:]
    return children