Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(161755)

Delta Between Two Patch Sets: Python/bltinmodule.c

Issue 23722: During metaclass.__init__, super() of the constructed class does not work
Left Patch Set: Created 3 years ago
Right Patch Set: Created 3 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « Objects/typeobject.c ('k') | Python/compile.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 /* Built-in functions */ 1 /* Built-in functions */
2 2
3 #include "Python.h" 3 #include "Python.h"
4 #include "Python-ast.h" 4 #include "Python-ast.h"
5 5
6 #include "node.h" 6 #include "node.h"
7 #include "code.h" 7 #include "code.h"
8 8
9 #include "asdl.h" 9 #include "asdl.h"
10 #include "ast.h" 10 #include "ast.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 _Py_IDENTIFIER(stdin); 47 _Py_IDENTIFIER(stdin);
48 _Py_IDENTIFIER(stdout); 48 _Py_IDENTIFIER(stdout);
49 _Py_IDENTIFIER(stderr); 49 _Py_IDENTIFIER(stderr);
50 50
51 #include "clinic/bltinmodule.c.h" 51 #include "clinic/bltinmodule.c.h"
52 52
53 /* AC: cannot convert yet, waiting for *args support */ 53 /* AC: cannot convert yet, waiting for *args support */
54 static PyObject * 54 static PyObject *
55 builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds) 55 builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
56 { 56 {
57 PyObject *func, *name, *bases, *mkw, *meta, *winner, *prep, *ns, *none; 57 PyObject *func, *name, *bases, *mkw, *meta, *winner, *prep, *ns;
58 PyObject *cls = NULL; 58 PyObject *cls = NULL, *cell = NULL;
59 Py_ssize_t nargs; 59 Py_ssize_t nargs;
60 int isclass = 0; /* initialize to prevent gcc warning */ 60 int isclass = 0; /* initialize to prevent gcc warning */
61 61
62 assert(args != NULL); 62 assert(args != NULL);
63 if (!PyTuple_Check(args)) { 63 if (!PyTuple_Check(args)) {
64 PyErr_SetString(PyExc_TypeError, 64 PyErr_SetString(PyExc_TypeError,
65 "__build_class__: args is not a tuple"); 65 "__build_class__: args is not a tuple");
66 return NULL; 66 return NULL;
67 } 67 }
68 nargs = PyTuple_GET_SIZE(args); 68 nargs = PyTuple_GET_SIZE(args);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 PyObject *pargs[2] = {name, bases}; 160 PyObject *pargs[2] = {name, bases};
161 ns = _PyObject_FastCallDict(prep, pargs, 2, mkw); 161 ns = _PyObject_FastCallDict(prep, pargs, 2, mkw);
162 Py_DECREF(prep); 162 Py_DECREF(prep);
163 } 163 }
164 if (ns == NULL) { 164 if (ns == NULL) {
165 Py_DECREF(meta); 165 Py_DECREF(meta);
166 Py_XDECREF(mkw); 166 Py_XDECREF(mkw);
167 Py_DECREF(bases); 167 Py_DECREF(bases);
168 return NULL; 168 return NULL;
169 } 169 }
170 none = PyEval_EvalCodeEx(PyFunction_GET_CODE(func), PyFunction_GET_GLOBALS(f unc), ns, 170 cell = PyEval_EvalCodeEx(PyFunction_GET_CODE(func), PyFunction_GET_GLOBALS(f unc), ns,
171 NULL, 0, NULL, 0, NULL, 0, NULL, 171 NULL, 0, NULL, 0, NULL, 0, NULL,
172 PyFunction_GET_CLOSURE(func)); 172 PyFunction_GET_CLOSURE(func));
173 if (none != NULL) { 173 if (cell != NULL) {
174 PyObject *margs[3] = {name, bases, ns}; 174 PyObject *margs[3] = {name, bases, ns};
175 cls = _PyObject_FastCallDict(meta, margs, 3, mkw); 175 cls = _PyObject_FastCallDict(meta, margs, 3, mkw);
176 Py_DECREF(none); 176 if (cls != NULL && PyType_Check(cls) && PyCell_Check(cell)) {
177 } 177 PyObject *cell_cls = PyCell_GET(cell);
178 if (cell_cls != cls) {
179 /* TODO: In 3.7, the deprecation warning becomes a RuntimeError
storchaka 2016/12/04 14:10:59 A dot is needed since the next line is a different
180 * At that point, cell_error won't be needed.
181 */
182 int cell_error;
183 if (cell_cls == NULL) {
184 const char *msg =
185 "__class__ not set defining %.200R as %.200R. "
186 "Was __classcell__ propagated to type.__new__?";
187 cell_error = PyErr_WarnFormat(
188 PyExc_DeprecationWarning, 1, msg, name, cls);
189 } else {
190 const char *msg =
191 "__class__ set to %.200R defining %.200R as %.200R.";
storchaka 2016/12/04 14:10:59 What about the ending dot? It usually is not used
192 PyErr_Format(PyExc_TypeError, msg, cell_cls, name, cls);
193 cell_error = 1;
194 }
195 if (cell_error) {
196 Py_DECREF(cls);
197 cls = NULL;
198 goto error;
199 } else {
200 /* Fill in the cell, since type.__new__ didn't do it */
201 PyCell_Set(cell, cls);
202 }
203 }
204 }
205 }
206 error:
207 Py_XDECREF(cell);
178 Py_DECREF(ns); 208 Py_DECREF(ns);
179 Py_DECREF(meta); 209 Py_DECREF(meta);
180 Py_XDECREF(mkw); 210 Py_XDECREF(mkw);
181 Py_DECREF(bases); 211 Py_DECREF(bases);
182 return cls; 212 return cls;
183 } 213 }
184 214
185 PyDoc_STRVAR(build_class_doc, 215 PyDoc_STRVAR(build_class_doc,
186 "__build_class__(func, name, *bases, metaclass=None, **kwds) -> class\n\ 216 "__build_class__(func, name, *bases, metaclass=None, **kwds) -> class\n\
187 \n\ 217 \n\
(...skipping 2523 matching lines...) Expand 10 before | Expand all | Expand 10 after
2711 if (PyDict_SetItemString(dict, "__debug__", debug) < 0) { 2741 if (PyDict_SetItemString(dict, "__debug__", debug) < 0) {
2712 Py_DECREF(debug); 2742 Py_DECREF(debug);
2713 return NULL; 2743 return NULL;
2714 } 2744 }
2715 Py_DECREF(debug); 2745 Py_DECREF(debug);
2716 2746
2717 return mod; 2747 return mod;
2718 #undef ADD_TO_ALL 2748 #undef ADD_TO_ALL
2719 #undef SETBUILTIN 2749 #undef SETBUILTIN
2720 } 2750 }
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+