Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
cleanup and clarification
  • Loading branch information
carljm committed Apr 20, 2023
commit f16126880434ee8ee005a6a00dcac9d86ff20720
24 changes: 12 additions & 12 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -9357,17 +9357,17 @@ super_repr(PyObject *self)
su->type ? su->type->tp_name : "NULL");
}

// if `method` is non-NULL, we are looking for a method descriptor,
// and setting `*method` to 1 means we found one.
static PyObject *
do_super_lookup(superobject *su, PyTypeObject *su_type, PyObject *su_obj,
Comment thread
carljm marked this conversation as resolved.
PyTypeObject *su_obj_type, PyObject *name, int *meth_found)
PyTypeObject *su_obj_type, PyObject *name, int *method)
{
PyTypeObject *starttype;
PyObject *mro, *res;
Py_ssize_t i, n;
int temp_su = 0;

starttype = su_obj_type;
if (starttype == NULL)
if (su_obj_type == NULL)
goto skip;

/* We want __class__ to return the class of the super object
Expand All @@ -9377,7 +9377,7 @@ do_super_lookup(superobject *su, PyTypeObject *su_type, PyObject *su_obj,
_PyUnicode_Equal(name, &_Py_ID(__class__)))
goto skip;

mro = starttype->tp_mro;
mro = su_obj_type->tp_mro;
if (mro == NULL)
goto skip;

Expand All @@ -9393,7 +9393,7 @@ do_super_lookup(superobject *su, PyTypeObject *su_type, PyObject *su_obj,
if (i >= n)
goto skip;

/* keep a strong reference to mro because starttype->tp_mro can be
/* keep a strong reference to mro because su_obj_type->tp_mro can be
replaced during PyDict_GetItemWithError(dict, name) */
Py_INCREF(mro);
do {
Expand All @@ -9404,8 +9404,8 @@ do_super_lookup(superobject *su, PyTypeObject *su_type, PyObject *su_obj,
res = PyDict_GetItemWithError(dict, name);
if (res != NULL) {
Py_INCREF(res);
if (meth_found && _PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR)) {
*meth_found = 1;
if (method && _PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR)) {
*method = 1;
}
else {
descrgetfunc f = Py_TYPE(res)->tp_descr_get;
Expand All @@ -9414,8 +9414,8 @@ do_super_lookup(superobject *su, PyTypeObject *su_type, PyObject *su_obj,
res2 = f(res,
/* Only pass 'obj' param if this is instance-mode super
(See SF ID #743627) */
(su_obj == (PyObject *)starttype) ? NULL : su_obj,
(PyObject *)starttype);
(su_obj == (PyObject *)su_obj_type) ? NULL : su_obj,
(PyObject *)su_obj_type);
Py_SETREF(res, res2);
}
}
Expand Down Expand Up @@ -9509,13 +9509,13 @@ supercheck(PyTypeObject *type, PyObject *obj)
}

PyObject *
_PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj, PyObject *name, int *meth_found)
_PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj, PyObject *name, int *method)
{
PyTypeObject *su_obj_type = supercheck(su_type, su_obj);
if (su_obj_type == NULL) {
return NULL;
}
PyObject *res = do_super_lookup(NULL, su_type, su_obj, su_obj_type, name, meth_found);
PyObject *res = do_super_lookup(NULL, su_type, su_obj, su_obj_type, name, method);
Py_DECREF(su_obj_type);
return res;
}
Expand Down
6 changes: 3 additions & 3 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1557,16 +1557,16 @@ dummy_func(
inst(LOAD_SUPER_ATTR, (global_super, class, self -- res2 if (oparg & 1), res)) {
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
if (global_super == (PyObject *)&PySuper_Type && PyType_Check(class)) {
int meth_found = 0;
int method = 0;
Py_DECREF(global_super);
res = _PySuper_Lookup((PyTypeObject *)class, self, name, oparg & 1 ? &meth_found : NULL);
res = _PySuper_Lookup((PyTypeObject *)class, self, name, oparg & 1 ? &method : NULL);
Py_DECREF(class);
if (res == NULL) {
Py_DECREF(self);
ERROR_IF(true, error);
}
// Works with CALL, pushes two values: either `meth | self` or `NULL | meth`.
if (meth_found) {
if (method) {
res2 = res;
res = self; // transfer ownership
} else {
Expand Down
Loading