コード例 #1
0
ファイル: rules.py プロジェクト: hsfzxjy/lambdex
def r_assign(node: ast.Compare, ctx: Context):
    try:
        *targets, value = check_compare(ctx, node,
                                        COMPARATORS[aliases.Assignment])
    except SyntaxError:
        return copy_lineinfo(
            node,
            ast.Expr(ctx.compile(node, flag=ContextFlag.should_be_expr)),
        )

    try_augassign = r_AugAssign(node, ctx, targets, value)
    if try_augassign is not None:
        return try_augassign

    for target in targets:
        ctx.assert_lvalue(target)
        cast_to_ctx(target)

    return copy_lineinfo(
        node,
        ast.Assign(
            targets=targets,
            value=ctx.compile(value),
        ),
    )
コード例 #2
0
def r_AugAssign(node: ast.Compare, ctx: Context, targets, value):
    if len(targets) != 1: return
    target = targets[0]
    if not isinstance(target, ast.BinOp) or not (isinstance(
            target.right, ast.Name) and target.right.id == '_'):
        return

    target, op = target.left, target.op
    ctx.assert_lvalue(target)
    cast_to_ctx(target)

    return copy_lineinfo(node, ast.AugAssign(target=target, op=op,
                                             value=value))
コード例 #3
0
ファイル: rules.py プロジェクト: hsfzxjy/lambdex
def r_del(node: ast.Subscript, ctx: Context, clauses: list, rule_id):
    ctx.assert_clause_num_at_most(clauses, 1)
    clause = clauses[0]
    ctx.assert_no_head(clause)

    targets = clause.body
    for target in targets:
        ctx.assert_lvalue(target, "cannot be deleted")
        target = cast_to_ctx(target, ast.Del())

    return copy_lineinfo(
        node,
        rule_id(targets=targets),
    )