summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c8
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);
}