summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2016-09-11 04:45:49 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2016-09-11 04:45:49 (GMT)
commit944368e1cc90a0bebaaf1a0a6f4346a81d8f46ad (patch)
treeea2c59fec386dfbe32c0f53ba8a85f75860e554d /Python/compile.c
parentfc3f7d56773b3816eb0e8f4151239a0983aedb2c (diff)
downloadcpython-944368e1cc90a0bebaaf1a0a6f4346a81d8f46ad.zip
cpython-944368e1cc90a0bebaaf1a0a6f4346a81d8f46ad.tar.gz
cpython-944368e1cc90a0bebaaf1a0a6f4346a81d8f46ad.tar.bz2
Issue #23722: Initialize __class__ from type.__new__()
The __class__ cell used by zero-argument super() is now initialized from type.__new__ rather than __build_class__, so class methods relying on that will now work correctly when called from metaclass methods during class creation. Patch by Martin Teichmann.
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 36683d3..4631dbb 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1968,7 +1968,7 @@ compiler_class(struct compiler *c, stmt_ty s)
return 0;
}
if (c->u->u_ste->ste_needs_class_closure) {
- /* return the (empty) __class__ cell */
+ /* store __classcell__ into class namespace */
str = PyUnicode_InternFromString("__class__");
if (str == NULL) {
compiler_exit_scope(c);
@@ -1981,15 +1981,20 @@ compiler_class(struct compiler *c, stmt_ty s)
return 0;
}
assert(i == 0);
- /* Return the cell where to store __class__ */
+
ADDOP_I(c, LOAD_CLOSURE, i);
+ str = PyUnicode_InternFromString("__classcell__");
+ if (!str || !compiler_nameop(c, str, Store)) {
+ Py_XDECREF(str);
+ compiler_exit_scope(c);
+ return 0;
+ }
+ Py_DECREF(str);
}
else {
+ /* This happens when nobody references the cell. */
assert(PyDict_Size(c->u->u_cellvars) == 0);
- /* This happens when nobody references the cell. Return None. */
- ADDOP_O(c, LOAD_CONST, Py_None, consts);
}
- ADDOP_IN_SCOPE(c, RETURN_VALUE);
/* create the code object */
co = assemble(c, 1);
}