diff options
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); |