diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2016-12-05 06:59:22 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2016-12-05 06:59:22 (GMT) |
commit | d77e5b7211e8daf22f2b3e0df124393bca504c38 (patch) | |
tree | 5e012ef2dbd2cf633d998cbb4ac780302bd30c73 /Python/compile.c | |
parent | de4ae3d4869e88dda8bfbad24880cb398160a7a0 (diff) | |
parent | 19d246745d9d013c12e9560dd020d778381780fb (diff) | |
download | cpython-d77e5b7211e8daf22f2b3e0df124393bca504c38.zip cpython-d77e5b7211e8daf22f2b3e0df124393bca504c38.tar.gz cpython-d77e5b7211e8daf22f2b3e0df124393bca504c38.tar.bz2 |
Merge #23722 from 3.6
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Python/compile.c b/Python/compile.c index 62f1c3f..76f08da 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1967,8 +1967,9 @@ compiler_class(struct compiler *c, stmt_ty s) compiler_exit_scope(c); return 0; } + /* Return __classcell__ if it is referenced, otherwise return None */ if (c->u->u_ste->ste_needs_class_closure) { - /* store __classcell__ into class namespace */ + /* Store __classcell__ into class namespace & return it */ str = PyUnicode_InternFromString("__class__"); if (str == NULL) { compiler_exit_scope(c); @@ -1983,6 +1984,7 @@ compiler_class(struct compiler *c, stmt_ty s) assert(i == 0); ADDOP_I(c, LOAD_CLOSURE, i); + ADDOP(c, DUP_TOP); str = PyUnicode_InternFromString("__classcell__"); if (!str || !compiler_nameop(c, str, Store)) { Py_XDECREF(str); @@ -1992,9 +1994,11 @@ compiler_class(struct compiler *c, stmt_ty s) Py_DECREF(str); } else { - /* This happens when nobody references the cell. */ + /* No methods referenced __class__, so just return None */ assert(PyDict_Size(c->u->u_cellvars) == 0); + ADDOP_O(c, LOAD_CONST, Py_None, consts); } + ADDOP_IN_SCOPE(c, RETURN_VALUE); /* create the code object */ co = assemble(c, 1); } |