diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2021-04-21 11:41:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-21 11:41:19 (GMT) |
commit | b0544ba77cf86074fb1adde00558c67ca75eeea1 (patch) | |
tree | 5168d0dc8da1360feabecfbc7c721b3fa9a38b11 /Python/ast_opt.c | |
parent | d35eef3b904b62e9c775bf3764ab0a0611f5a860 (diff) | |
download | cpython-b0544ba77cf86074fb1adde00558c67ca75eeea1.zip cpython-b0544ba77cf86074fb1adde00558c67ca75eeea1.tar.gz cpython-b0544ba77cf86074fb1adde00558c67ca75eeea1.tar.bz2 |
bpo-38605: Revert making 'from __future__ import annotations' the default (GH-25490)
This reverts commits 044a1048ca93d466965afc027b91a5a9eb9ce23c and 1be456ae9d53bb1cba2b24fc86175c282d1c2169, adapting the code to changes that happened after it.
Diffstat (limited to 'Python/ast_opt.c')
-rw-r--r-- | Python/ast_opt.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Python/ast_opt.c b/Python/ast_opt.c index 311e0c7..dea20da 100644 --- a/Python/ast_opt.c +++ b/Python/ast_opt.c @@ -406,6 +406,7 @@ static int astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTOptimizeState *state static int astfold_arguments(arguments_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); static int astfold_comprehension(comprehension_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); static int astfold_keyword(keyword_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); +static int astfold_arg(arg_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); static int astfold_withitem(withitem_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); static int astfold_excepthandler(excepthandler_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); static int astfold_match_case(match_case_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); @@ -625,12 +626,26 @@ astfold_comprehension(comprehension_ty node_, PyArena *ctx_, _PyASTOptimizeState static int astfold_arguments(arguments_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) { + CALL_SEQ(astfold_arg, arg, node_->posonlyargs); + CALL_SEQ(astfold_arg, arg, node_->args); + CALL_OPT(astfold_arg, arg_ty, node_->vararg); + CALL_SEQ(astfold_arg, arg, node_->kwonlyargs); CALL_SEQ(astfold_expr, expr, node_->kw_defaults); + CALL_OPT(astfold_arg, arg_ty, node_->kwarg); CALL_SEQ(astfold_expr, expr, node_->defaults); return 1; } static int +astfold_arg(arg_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) +{ + if (!(state->ff_features & CO_FUTURE_ANNOTATIONS)) { + CALL_OPT(astfold_expr, expr_ty, node_->annotation); + } + return 1; +} + +static int astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) { switch (node_->kind) { @@ -638,11 +653,17 @@ astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) CALL(astfold_arguments, arguments_ty, node_->v.FunctionDef.args); CALL(astfold_body, asdl_seq, node_->v.FunctionDef.body); CALL_SEQ(astfold_expr, expr, node_->v.FunctionDef.decorator_list); + if (!(state->ff_features & CO_FUTURE_ANNOTATIONS)) { + CALL_OPT(astfold_expr, expr_ty, node_->v.FunctionDef.returns); + } break; case AsyncFunctionDef_kind: CALL(astfold_arguments, arguments_ty, node_->v.AsyncFunctionDef.args); CALL(astfold_body, asdl_seq, node_->v.AsyncFunctionDef.body); CALL_SEQ(astfold_expr, expr, node_->v.AsyncFunctionDef.decorator_list); + if (!(state->ff_features & CO_FUTURE_ANNOTATIONS)) { + CALL_OPT(astfold_expr, expr_ty, node_->v.AsyncFunctionDef.returns); + } break; case ClassDef_kind: CALL_SEQ(astfold_expr, expr, node_->v.ClassDef.bases); @@ -666,6 +687,9 @@ astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) break; case AnnAssign_kind: CALL(astfold_expr, expr_ty, node_->v.AnnAssign.target); + if (!(state->ff_features & CO_FUTURE_ANNOTATIONS)) { + CALL(astfold_expr, expr_ty, node_->v.AnnAssign.annotation); + } CALL_OPT(astfold_expr, expr_ty, node_->v.AnnAssign.value); break; case For_kind: |