def _check_For_stmt(stmt, env): """For Loop.""" assert stmt.__class__ is ast.For x = stmt.target e = stmt.iter b0 = stmt.body b1 = stmt.orelse x_t = infer_expr(x, env) # (For) assignment rule. -- restricted by type inference return (x_t and check_expr(e, PType.list(x_t), env) and check_stmt_list(b0, env) and check_stmt_list(b1, env))
def infer_List_expr(lst, env): """ Determine the type of AST `List` expression under type environment `env`. `ast.List` - `elts`: Python list of contained expr nodes - `ctx': context of the expr (e.g., load, store) """ assert lst.__class__ is ast.List elts_list = lst.elts first_type = infer_expr(elts_list[0], env) if all(check.check_expr(e, first_type, env) for e in elts_list[1:]): # (lst) assignment rule. return PType.list(first_type) else: # No assignment rule found. return None