From 015d8746261f23084d449ae9f382d7088ec7016f Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sun, 11 Sep 2016 09:45:24 -0700 Subject: Issue #28076: Variable annotations should be mangled for private names. By Ivan Levkivskyi. --- Python/compile.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Python/compile.c') diff --git a/Python/compile.c b/Python/compile.c index 6d64c076e10..6bab86eb0ba 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -4562,6 +4562,7 @@ static int compiler_annassign(struct compiler *c, stmt_ty s) { expr_ty targ = s->v.AnnAssign.target; + PyObject* mangled; assert(s->kind == AnnAssign_kind); @@ -4576,8 +4577,13 @@ 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)) { + mangled = _Py_Mangle(c->u->u_private, targ->v.Name.id); + if (!mangled) { + return 0; + } VISIT(c, expr, s->v.AnnAssign.annotation); - ADDOP_O(c, STORE_ANNOTATION, targ->v.Name.id, names) + /* ADDOP_N decrefs its argument */ + ADDOP_N(c, STORE_ANNOTATION, mangled, names); } break; case Attribute_kind: -- cgit v1.2.3