summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-08-19 08:04:07 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2016-08-19 08:04:07 (GMT)
commit3f015a64b83fd243c165147d225cb37dc7e3e645 (patch)
tree051733732e931ef146f3da1b4509d87382d90cff /Objects
parent2a400fd62a292e43df75ca687c4d350e9a98af44 (diff)
downloadcpython-3f015a64b83fd243c165147d225cb37dc7e3e645.zip
cpython-3f015a64b83fd243c165147d225cb37dc7e3e645.tar.gz
cpython-3f015a64b83fd243c165147d225cb37dc7e3e645.tar.bz2
Issue #27157: Make only type() itself accept the one-argument form
Patch by Eryk Sun and Emanuel Barry.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 1b4c261..d141bf4 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2287,11 +2287,13 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
assert(kwds == NULL || PyDict_Check(kwds));
/* Special case: type(x) should return x->ob_type */
- {
+ /* We only want type itself to accept the one-argument form (#27157)
+ Note: We don't call PyType_CheckExact as that also allows subclasses */
+ if (metatype == &PyType_Type) {
const Py_ssize_t nargs = PyTuple_GET_SIZE(args);
const Py_ssize_t nkwds = kwds == NULL ? 0 : PyDict_Size(kwds);
- if (PyType_CheckExact(metatype) && nargs == 1 && nkwds == 0) {
+ if (nargs == 1 && nkwds == 0) {
PyObject *x = PyTuple_GET_ITEM(args, 0);
Py_INCREF(Py_TYPE(x));
return (PyObject *) Py_TYPE(x);
@@ -2308,8 +2310,8 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
}
/* Check arguments: (name, bases, dict) */
- if (!PyArg_ParseTuple(args, "UO!O!:type", &name, &PyTuple_Type, &bases,
- &PyDict_Type, &orig_dict))
+ if (!PyArg_ParseTuple(args, "UO!O!:type.__new__", &name, &PyTuple_Type,
+ &bases, &PyDict_Type, &orig_dict))
return NULL;
/* Determine the proper metatype to deal with this: */