From b0544ba77cf86074fb1adde00558c67ca75eeea1 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Wed, 21 Apr 2021 12:41:19 +0100 Subject: 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. --- Python/compile.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'Python/compile.c') diff --git a/Python/compile.c b/Python/compile.c index 496b4b0371f..49a713b2b0c 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -2111,16 +2111,24 @@ static int compiler_visit_argannotation(struct compiler *c, identifier id, expr_ty annotation, Py_ssize_t *annotations_len) { - if (annotation) { - PyObject *mangled = _Py_Mangle(c->u->u_private, id); - if (!mangled) - return 0; + if (!annotation) { + return 1; + } + + PyObject *mangled = _Py_Mangle(c->u->u_private, id); + if (!mangled) { + return 0; + } + ADDOP_LOAD_CONST(c, mangled); + Py_DECREF(mangled); - ADDOP_LOAD_CONST(c, mangled); - Py_DECREF(mangled); - VISIT(c, annexpr, annotation); - *annotations_len += 2; + if (c->c_future->ff_features & CO_FUTURE_ANNOTATIONS) { + VISIT(c, annexpr, annotation) + } + else { + VISIT(c, expr, annotation); } + *annotations_len += 2; return 1; } @@ -5403,7 +5411,12 @@ compiler_annassign(struct compiler *c, stmt_ty s) if (s->v.AnnAssign.simple && (c->u->u_scope_type == COMPILER_SCOPE_MODULE || c->u->u_scope_type == COMPILER_SCOPE_CLASS)) { - VISIT(c, annexpr, s->v.AnnAssign.annotation); + if (c->c_future->ff_features & CO_FUTURE_ANNOTATIONS) { + VISIT(c, annexpr, s->v.AnnAssign.annotation) + } + else { + VISIT(c, expr, s->v.AnnAssign.annotation); + } ADDOP_NAME(c, LOAD_NAME, __annotations__, names); mangled = _Py_Mangle(c->u->u_private, targ->v.Name.id); ADDOP_LOAD_CONST_NEW(c, mangled); -- cgit v1.2.3