def build_AnnAssign(ctx, stmt): if stmt.value is None: raise UnsupportedNodeError(ctx, stmt, reason='without assigned value') rhs = build_expr(ctx, stmt.value) lhs = build_expr(ctx, stmt.target) the_type = build_expr(ctx, stmt.annotation) return Assign([lhs], rhs, the_type)
def build_AnnAssign(ctx, stmt): if stmt.value is None: raise UnsupportedNodeError(ctx, stmt, reason='without assigned value') # Disallow type annotations on instance attributes outside of __init__ if type(stmt.target) == ast.Attribute and \ stmt.target.value.id == "self" and ctx.funcname != "__init__": # type: ignore[attr-defined] start = stmt.col_offset end = start + len(f"self.{stmt.target.attr}") if hasattr(stmt.annotation, 'id'): end += len(f": {stmt.annotation.id}") sr = ctx.make_range(stmt.lineno, start, end) raise ValueError("Type annotations on instance attributes must be declared in " f"__init__, not '{ctx.funcname}': {sr}") rhs = build_expr(ctx, stmt.value) lhs = build_expr(ctx, stmt.target) the_type = build_expr(ctx, stmt.annotation) return Assign([lhs], rhs, the_type)
def build_Assign(ctx, stmt): rhs = build_expr(ctx, stmt.value) lhs = [build_expr(ctx, x) for x in stmt.targets] return Assign(lhs, rhs)
def build_Assign(ctx, stmt): rhs = build_expr(ctx, stmt.value) lhs = list(map(lambda x: build_expr(ctx, x), stmt.targets)) return Assign(lhs, rhs)
def build_Assign(ctx, stmt): # build_expr是ExprBuilder的INSTANCE,其会调用`build_BinOp` rhs = build_expr(ctx, stmt.value) lhs = [build_expr(ctx, x) for x in stmt.targets] return Assign(lhs, rhs)