Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/test/test_super.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ def method(self, type_, obj):
with self.assertRaisesRegex(TypeError, regex):
c.method(type_, obj)

def test_supercheck_uninitialized_super(self):
s = super.__new__(super)
with self.assertRaisesRegex(TypeError, "super object has no type"):
s.__get__(1)

def test_super___class__(self):
class C:
def method(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a crash in :func:`super` when an uninitialized ``super`` object created
with ``super.__new__(super)`` was used as a descriptor.
9 changes: 7 additions & 2 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -12562,6 +12562,12 @@ supercheck(PyTypeObject *type, PyObject *obj)
This will allow using super() with a proxy for obj.
*/

if (type == NULL) {
PyErr_SetString(PyExc_TypeError,
"super object has no type");
return NULL;
}

/* Check for first bullet above (special case) */
if (PyType_Check(obj) && PyType_IsSubtype((PyTypeObject *)obj, type)) {
return (PyTypeObject *)Py_NewRef(obj);
Expand Down Expand Up @@ -12642,8 +12648,7 @@ super_descr_get(PyObject *self, PyObject *obj, PyObject *type)
PyTypeObject *obj_type = supercheck(su->type, obj);
if (obj_type == NULL)
return NULL;
newobj = (superobject *)PySuper_Type.tp_new(&PySuper_Type,
NULL, NULL);
newobj = (superobject *)PySuper_Type.tp_alloc(&PySuper_Type, 0);
if (newobj == NULL) {
Py_DECREF(obj_type);
return NULL;
Expand Down
Loading