mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-23722: Raise a RuntimeError for absent __classcell__. (GH-6931)
A DeprecationWarning was emitted in Python 3.6-3.7.
This commit is contained in:
parent
8ae8e6af37
commit
f5e7b1999f
5 changed files with 24 additions and 51 deletions
|
@ -254,30 +254,19 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs,
|
|||
if (cls != NULL && PyType_Check(cls) && PyCell_Check(cell)) {
|
||||
PyObject *cell_cls = PyCell_GET(cell);
|
||||
if (cell_cls != cls) {
|
||||
/* TODO: In 3.7, DeprecationWarning will become RuntimeError.
|
||||
* At that point, cell_error won't be needed.
|
||||
*/
|
||||
int cell_error;
|
||||
if (cell_cls == NULL) {
|
||||
const char *msg =
|
||||
"__class__ not set defining %.200R as %.200R. "
|
||||
"Was __classcell__ propagated to type.__new__?";
|
||||
cell_error = PyErr_WarnFormat(
|
||||
PyExc_DeprecationWarning, 1, msg, name, cls);
|
||||
PyErr_Format(PyExc_RuntimeError, msg, name, cls);
|
||||
} else {
|
||||
const char *msg =
|
||||
"__class__ set to %.200R defining %.200R as %.200R";
|
||||
PyErr_Format(PyExc_TypeError, msg, cell_cls, name, cls);
|
||||
cell_error = 1;
|
||||
}
|
||||
if (cell_error) {
|
||||
Py_DECREF(cls);
|
||||
cls = NULL;
|
||||
goto error;
|
||||
} else {
|
||||
/* Fill in the cell, since type.__new__ didn't do it */
|
||||
PyCell_Set(cell, cls);
|
||||
}
|
||||
Py_DECREF(cls);
|
||||
cls = NULL;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue