summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@dropbox.com>2016-09-11 16:45:24 (GMT)
committerGuido van Rossum <guido@dropbox.com>2016-09-11 16:45:24 (GMT)
commit015d8746261f23084d449ae9f382d7088ec7016f (patch)
tree54a689b42bfa979d7975f3006951d795a891b509 /Python
parenta6d75fdc37e4cbc49fe64420219f3b4da1b20cef (diff)
downloadcpython-015d8746261f23084d449ae9f382d7088ec7016f.zip
cpython-015d8746261f23084d449ae9f382d7088ec7016f.tar.gz
cpython-015d8746261f23084d449ae9f382d7088ec7016f.tar.bz2
Issue #28076: Variable annotations should be mangled for private names.
By Ivan Levkivskyi.
Diffstat (limited to 'Python')
-rw-r--r--Python/compile.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 6d64c07..6bab86e 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: