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/compile.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/compile.c')
-rw-r--r-- | Python/compile.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/Python/compile.c b/Python/compile.c index 496b4b0..49a713b 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); |